Multiple sample values into scatteredInterpolant

1 view (last 30 days)
i have been trying to interpolate the wind speed of a known location on a meshed grid with changing sampe values (wind speed) recorded at weather station locations, the function below works for one value.
But how can i use all of the hourly data from 11 weather stations (2013-2019) this is a 48764x11 matrix (48764 data points for the 11 different weather station locations?
at the minute i can run it for a single hour of data by using B{1} (first hour) and this works well but is there a way to use B{1: 48764} for the separate hourly data inputs
the example below gives the output data for the first hour ( B{1} ) what i am looking for is all of the hours = 48764 values
Note - dataS1 = 48764x11 matrix imported from excel
Thanks in advance,
close all; clc;
lat = [51.0059, 51.1613, 51.2012, 51.0864, 51.8603, 51.5028, 52.0796, 52.1480, 52.0629, 52.2426, 51.4050]';%latitude of 11 weather stations%
lon = [-2.6415, -1.7532, -1.8044, -3.6077, -1.6915, -1.9909, -2.8010, -2.0398, -3.6134, -2.8845, -3.4395]';%longitude of 11 weather stations%
A = [dataS1]; %this is a 48764x11 matrix imported from an excel file
B = num2cell(A,2);
lon0 = min(lon) ; lon1 = max(lon) ;
lat0 = min(lat) ; lat1 = max(lat) ;
latlim=[lat0 lat1]; lonlim=[lon0 lon1] ;
lon0 = min(lon) ; lon1 = max(lon) ;
lat0 = min(lat) ; lat1 = max(lat) ;
N = 100 ;
x = linspace(lon0,lon1,N) ;
y = linspace(lat0,lat1,N) ;
[X,Y] = meshgrid(x,y) ;
F = scatteredInterpolant(lon,lat,B{1}') ;
Z = F(X,Y) ;
%extract data
Yq = 51.5055 ; %target location longitude
Xq = -2.71532 ; %target location latitude
Vq = F(Xq,Yq)

Answers (1)

Sargondjani on 6 Apr 2021
What works is: Make a 3D array from B, so:
for ih=1:length(B)
B_3D(:,:,id) = B{ib)
And then add a vector 'hours' as third dimension to interpolant.
There's probably more fancy ways to do this, but it will work
Sargondjani on 6 Apr 2021
Sorry man, I dont have time to give you a full answer. You should play around. Maybe skip the 'num2cell' or something.
Example: A=[10x5x21] array, then to interpolate on x1 (1x10), x2 (1x5) and x3 (1x21) by calling:
[X1,X2,X3] = ndgrid(x1,x2,x3);%expand the vectors such that they have the same size as A
FF = griddedInterpolant(X1,X2,X3,A);
You need to do something similar. Make sure X1, X2, X3 and A have to same dimensions

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!