Further question about using pcolor

Dear MATLAB wizard,
I have read and used the answers that you gave to Alan B's question of a few days ago. I, too, am attempting to put concentrations on a map. I have uploaded my data from Excel, and split the latitude (LatDIC), longitude (LongDIC) and concentration (DIC) data into separate matrices that are one column of data each. I keep getting an error because pcolor does not seem to like that my data is not in a wide matrix.
figure(1); pcolor(LongDIC,LatDIC,DIC), shading flat, colorbar, title('DIC');
I have been trying to average the data using some code sent to me by someone else, but I am having problems because I don't know what their data set looked like to begin with. I have copied their code below.
% calculate out averages for each latitudinal band
% discard any cells where any data is not available
if isfinite(gd_co3a(ii,jj,1))
atl_co3_gd(ilat) = atl_co3_gd(ilat) + gd_co3a(ii,jj,1);
c_atl_co3_gd(ilat) = c_atl_co3_gd(ilat) + 1.0;
end;
if isfinite(pred_co3(ii,jj,1))
atl_co3_p1(ilat) = atl_co3_p1(ilat) + pred_co3(ii,jj,1);
c_atl_co3_p1(ilat) = c_atl_co3_p1(ilat) + 1.0;
end;
if isfinite(pred_co3_2(ii,jj,1))
atl_co3_p2(ilat) = atl_co3_p2(ilat) + pred_co3_2(ii,jj,1);
c_atl_co3_p2(ilat) = c_atl_co3_p2(ilat) + 1.0;
end;
if isfinite(woa_sal(ii,jj,1))
atl_sal(ilat) = atl_sal(ilat) + woa_sal(ii,jj,1);
c_atl_sal(ilat) = c_atl_sal(ilat) + 1.0;
end;
or this code:
% calculate averages for each latitudinal band
if (c_co3_gd(ilat) > 5)
co3_gd(ilat) = co3_gd(ilat) / c_co3_gd(ilat);
else
co3_gd(ilat) = NaN;
end;
if (c_co3_pred1(ilat) > 5)
co3_pred1(ilat) = co3_pred1(ilat) / c_co3_pred1(ilat);
else
co3_pred1(ilat) = NaN;
end;
I think that I might need to initialise the original matrices to zeros(181,361) with the data in the first row.
Am I on the right track? Any suggestions would be appreciated.
Many thanks!

 Respuesta aceptada

Kelly Kearney
Kelly Kearney el 24 de Ag. de 2011

0 votos

How is your data distributed, geographically? Is it located on a grid? If so, you just need to rearrange the data into the appropriate grid before feeding it to pcolor.
If the data is scattered, you can either plot discrete points or interpolate onto a grid and plot via pcolor. A few helpful functions
reshape
scatter
TriScatteredInterp
griddata

2 comentarios

Jen
Jen el 26 de Ag. de 2011
Thanks, Kelly. You are right--they are not on a grid. I have tried to grid the data using griddata:
DICLat=data(:,1);
DICLong=data(:,2);
DIC=zeros(83);
DIC=data(:,13);
XIDIC=[-3:0.5:10];
YIDIC=[49:0.5:62];
YIDIC2(:,1)=YIDIC(1,:);
ZIDIC=griddata(DICLat,DICLong,DIC,XIDIC,YIDIC2);
but it comes up with a matrix that is entirely NaN! Oh no! There is no error message. I was planning then to do:
figure(1); pcolor(XIDIC,YIDIC,ZIDIC), shading flat, colorbar, title('DIC');
Any thoughts on why my ZIDIC matrix is NaN?
Thanks again for your help!
Jen
Jen el 27 de Ag. de 2011
Ah..I needed to use meshgrid. I have sorted it out now and got both pcolor and contour maps. Many thanks for your help! This forum is an invaluable resource.

Iniciar sesión para comentar.

Más respuestas (1)

Fangjun Jiang
Fangjun Jiang el 24 de Ag. de 2011
To visualize a series of (x,y,z) data, I made the following example. The first part is just to come up with some data. The second part is the visualization.
Note that the pcolor() in figure 1 has 9x9 patch of colors. The 2-D view of the scatter3() in figure(3) has 10x10 squares of colors. So ignore the first row and last column of figure(3) you will get a 100% match of colors. Adjust the size of the square to achieve the desired results.
close all;
N=10;z=rand(N);
x=repmat(1:N,N,1);
y=repmat((1:N)',1,N);
X=x(:);Y=y(:);Z=z(:);
CircleSize=1500;
figure;pcolor(z);
figure;h1=stem3(X,Y,Z,'filled');
figure;h2=scatter3(X,Y,Z,CircleSize,Z,'s','filled');
view(2);

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

Jen
el 24 de Ag. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by