# Accessing (interpolating?) data in 3D array

2 views (last 30 days)
Louise Wilson on 25 Nov 2021
Commented: Louise Wilson on 28 Nov 2021
I have been using Matlab for many years but this is my first time working with a 3D array. My data is 290x480x90 in the format latitude x longitude x frequency. So it contains sound pressure data for a range of locations at different frequencies. I am wondering if I could then create a separate array e.g. 10x2x1 of lat/lon locations at a particular freq of interest that lie within the main array, and pull those data points out? Those specific locations of interest therefore don't necessarily occur as points of the 3D array but they are within it... hopefully that makes sense.
Louise Wilson on 28 Nov 2021
I have two devices, one with 2020b and one with 2021a (University issues...), it works the same as you in 2020b but in 2021a squeeze is needed.

Matt J on 25 Nov 2021
Edited: Matt J on 25 Nov 2021
You could use griddedInterpolant()
array=rand(290,480,90);
F=griddedInterpolant(array);
extract=F({linspace(4,8,10), 400:401, 80.1}) %10x2 area extracted at frequency=80.1
Louise Wilson on 28 Nov 2021
Hi Matt, I understand that you created an array of 10 values and two rows as data points to extract for the frequency 80.1.
I understand that for my purposes I would want to replace these values with lat and lon
linspace(4,8,10) %becomes lat
400:401 %becomes lon
whos vardata
Name Size Bytes Class Attributes
vardata 91x489x280 49838880 single
%where 91 is frequency, 489 is longitude, 280 is latitude (I got this wrong
%in OP sorry)
%x2 is a 7200x1 array of longitude of interest (attached)
%y2 is a 7200x1 array of latitude of interest (attached)
F=griddedInterpolant(vardata);
%vardata (freq, lon, lat)
extract=F({30,x2,y2});
extract=squeeze(extract);
[row,col]=find(~isnan(extract));
row =
0×1 empty double column vector
col =
0×1 empty double column vector
and whilst this 'works', it returns NaN for all values.
I have attached a visual display of what I am trying to do. The vardata array is illustrated by the pcolor plot where the colorbar is data for the frequency '30'. On top of this I have displayed the dummy data points which I would like to extract data for (x2,y2). For every blue point, I want to know the value in the pcolor plot. The white area is land so I expect that to be NaN.
Here is the code for the figure
% Plot map
[p,m,n] = size(vardata) ;
for i = 30 %for frequency 30
pcolor(H_londata,H_latdata,squeeze(vardata(i,:,:))');
drawnow
end
hold on
mapshow(x2,y2) %points of interest for which to extract data
colorbar
caxis([0 100])

R2021a

### Community Treasure Hunt

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

Start Hunting!