surface plot of cell arrays

10 vues (au cours des 30 derniers jours)
Moes
Moes le 15 Juin 2011
Hi,
I am wondering if it's possible to (at least mimic) surf/surc functions with cell arrays with each element having a different length (i.e. not a simple rectangular matrix). I am most interested in the color coding of values so that a 2D view of the plot conveys the magnitude of the function plotted.
Cheers

Réponse acceptée

Moes
Moes le 15 Juin 2011
Bugger!
My aim in using cell arrays is to minimize number of calculations done. Here are simplified versions of what I have and what I want:
% Code I have (computationally intensive)
divs_x = 10;
D_x = linspace(1, divs_x, divs_x);
divs_y = 5*max(D_x);
D_y = linspace(0, pi, divs_y);
z = zeros(divs_x, divs_y);
for k = 1 : divs_x,
z(k, :) = cos(D_y);
end;
surf(D_y, D_x, z);
colormap(hot(128));
colorbar;
% Code I want but cannot plot
divs_x = 10;
D_x = linspace(1, divs_x, divs_x);
z = cell(1, divs_x);
D_y = cell(1, divs_x);
for k = 1 : divs_x,
divs_y = 5*D_x(k);
D_y{k} = linspace(0, pi, divs_y);
z{k} = cos(D_y{k});
end;
I could use plot3 to plot individual cells but it won't produce the color mapping that I want. I am not terribly concerned with filled surfaces (but would be nice).
  6 commentaires
Walter Roberson
Walter Roberson le 15 Juin 2011
pointsize = 8;
scatter3(D_x(i)*ones(1,length(D_y{i})), D_y{i}, z{i}, pointsize, z{i});
Moes
Moes le 15 Juin 2011
Ha! Fantastic.
Changing the pointsize to something a bit larger and also having it "filled" produces a very much acceptable plot when the stepsize in D_x and D_y domains are small. Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 15 Juin 2011
Not with cell arrays. You could use patch() though.
On the other hand, I am not sure why you don't use
surf(X,Y,Z,Z)
as that would use the Z value to interpolate the Color

Community Treasure Hunt

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

Start Hunting!

Translated by