Effacer les filtres
Effacer les filtres

Multiple sample values into scatteredInterpolant

2 vues (au cours des 30 derniers jours)
Alfred Ruff
Alfred Ruff le 6 Avr 2021
Commenté : Sargondjani le 6 Avr 2021
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)

Réponses (1)

Sargondjani le 6 Avr 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
  2 commentaires
Alfred Ruff
Alfred Ruff le 6 Avr 2021
Modifié(e) : Alfred Ruff le 6 Avr 2021
Hi Sargondjani,
Thanks for the reply i think you are correct this will work!however i am having an issue with the following error:
"Conversion to cell from double is not possible."
have you managed to get the code to work? can you please show me where and how you have modifyed the code that i put in the orginal post?
Sargondjani le 6 Avr 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

Connectez-vous pour commenter.


En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by