Reading and visualizing netcdf with vectors of differing lengths

This is my first time reading netcdf data. I can read the file and variables of interest as follows:
vardata=ncread('TL__Map1_15C_sand1__20mres_-36.265137N_174.790466','TLdata');
H_latdata=ncread('TL__Map1_15C_sand1__20mres_-36.265137N_174.790466','H_latdata');
H_londata=ncread('TL__Map1_15C_sand1__20mres_-36.265137N_174.790466','H_londata');
H_freqdata=ncread('TL__Map1_15C_sand1__20mres_-36.265137N_174.790466','H_freqdata');
Unfortunately I cannot attach the file because even in Zip format it is greater than 5mb.
>> whos vardata
Name Size Bytes Class Attributes
vardata 91x489x280 49838880 single
I'd like to be able to plot/visualize the data, but when I try to use plot3() it tells me the vectors must be the same length. Is there another way?
My goal is to find the freq value for a specific lat/lon, but in order to do make a selection of positions of interest, I need to look at the positions I have and see how they vary.

 Accepted Answer

If you want to attach the file, you can upload in some cloud spaces (google drive) and share the link here without asking the login's credentials.
[p,m,n] = size(vardata) ;
for i = 1:p
pcolor(H_londata,H_latdata,squeeze(vardata(i,:,:))') ;
shading interp
drawnow
end
If you want to extract a series from the (i,j) position
i = 3 ;
j = 4 ;
v = squeeze(vardata(:,j,i)) ;
plot(v)

8 Comments

When I try the first chunk of code, I get an error that the matrix dimensions must agree.
Check your data.....edited the code......Try running like shown.
That also does not work :(
>> [m,n,p] = size(vardata) ;
for i = 1:p
pcolor(H_londata,H_latdata,vardata(:,:,i)') ;
shading interp
drawnow
end
Error using pcolor (line 61)
Matrix dimensions must agree.
You will see in the data that some of the values are NaN, could that be an issue? They could be replaced with zeroes.
I tried this, but no joy...
vardata(isnan(vardata))=0;
[m,n,p] = size(vardata) ;
for i = 1:p
pcolor(H_londata,H_latdata,vardata(i,:,:)') ;
shading interp
drawnow
end
Error using '
Transpose on ND array is not defined. Use PERMUTE instead.
No NaN is not the issue, the dimensions are issue. Edited the code. Hope you have noticed it.
Ooh it looks awesome, thank you so much!
Is the second part for extracting specific data from a lat/lon still okay?
I'd like to input a specific lat (n) /lon (m) and get the p value.
j=6.291 %lon
i=-3.257 %lat
v = squeeze(vardata(:,j,i)) ;
Index in position 2 is invalid. Array indices must be positive
integers or logical values.
i, j should be indices, not lon/ lat values.
Also note that H_londata,H_latdata are not in degrees. If you have fixed i, j as values instead of the indices, Use:
idx = knnsearch([X(:) Y(:)],[i j]) ;
[r,c] = ind2sub(size(X),idx) ;
v = squeeze(vardata(:,r,c)) ;
And thanks is accepting/ voting the answer. :)
Done :) Thank you!
They are in UTM so a coordinate format just different to decimal degrees. I will try your suggestion, thank you.

Sign in to comment.

More Answers (0)

Products

Release

R2020a

Tags

Asked:

on 23 Nov 2021

Commented:

on 23 Nov 2021

Community Treasure Hunt

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

Start Hunting!