Index in position 2 exceeds array bounds (must not exceed 101)
Show older comments
I would appreciate any help on this. Problem is defining 'newsst', i have tried with also with a loop (commented) but theres something dimension wise i dont get..
Have attached the data and hope the code is descriptive enough.
% load and store netcdf file variables in separate matrices
ncdisp('sst_2015.nc')
sst = ncread('sst_2015.nc','sea_surface_temperature');
time = ncread('sst_2015.nc','time');
lat = ncread('sst_2015.nc','lat'); %latitude
lon = ncread('sst_2015.nc','lon'); %longitude
%exclude potential values from outside the defined box of coordinates below
% Note: use of '&&' instead of '&' below creates an error: 'Operands to the || and &&
% operators must be convertible to logical scalar values'. Works with '&',
% not sure if correct.
newlat = find(lat>50&lat<60);
newlon = find(lon>-3&lon<11);
%change to desired degree of resolution for latitude and longitude
ds_lat=0.1000;
ds_lon = 0.1666;
lati=50:ds_lat:60;
loni=-3:ds_lon:11;
[Loni,Lati] = meshgrid(loni,lati) ;
newsst = sst(newlat,newlon,time);
% newsst = zeros (i,j,k); i,j,k loop base on dimensions of sst
% for i=1:140
% for j=1:101
% for k=1:355
%
% newsst = sst(newlat(i),newlon(j),time(k));
%
% end
%
% end
% end
%interpolate and put everything in a new grid. we will now have values on same
%lat and lon points defined by Loni and Lati
NEWSST = griddata (Loni,Lati,newlat,newlon,newsst);
Accepted Answer
More Answers (1)
Guillaume
on 18 Mar 2019
My guess is that you want all the times, in which case:
newsst = sst(newlat, newlon, :);
Using time as an index into newsst makes no sense.
Note that you don't need find, it's just a waste of time. You can use the logical array directly to index sst:
newlat = lat>50 & lat<60; %find not required. Just extra processing for no reason
newlon = lon>-3 & lon<11; %same
newsst = sst(newlat, newlon, :);
Categories
Find more on Antennas, Microphones, and Sonar Transducers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!