0

I want to read multiple nc files from a folder. these files are in matrix form i.e. layer wise data. i have successfully read a single file and display the attributes and also extract them. but when i tried to plot them, it ends with the error. i am new to MATLAB so i don't know what kind of error is this and how to fix it. I also have to read multiple files and create a separate data frame with desired variables. i have tried this code:`

    filename='1.nc';
    ncdisp(filename);
    lat=ncread(filename,'latitude');
    lon=ncread(filename,'longitude');
    time=ncread(filename,'time');
    vertical=ncread(filename,'D_vertical_profile')
    mymap=pcolor(lat,lon,time)`

it comes with the error

Error using pcolor (line 57) Matrix dimensions must agree.

Qaim
  • 1
  • 1

1 Answers1

0

Following the official documentation:

pcolor(X,Y,C) draws a pseudocolor plot of the elements of C at the locations specified by X and Y

So:

ncfile = 'C:\Path\To\File\1.nc';

lon = ncread(ncfile,'longitude');
lat = ncread(ncfile,'latitude');
time = ncread(ncfile,'time');

tco = ncread(ncfile,'TCO');
[x,y] = meshgrid(lon,lat);

for i = 1:length(time)
    pcolor(x,y,tco(:,:,i)');
    shading interp;
    title(sprintf('time = %f',time(i)));

    pause(0.1);
end
Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
  • Thanks for replying. It is coming up with the same error that 'Matrix dimensions must agree'. Actually the vertical data is in the form of layers i.e. in six columns against the same lat longs. Lat, longs, and time is shown in single column. My question is how to make a table or data frame of time, lat, long and vertical data ? – Qaim Nov 12 '17 at 08:28