surface plot of cell arrays

9 次查看(过去 30 天)
Moes
Moes 2011-6-15
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

采纳的回答

Moes
Moes 2011-6-15
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 个评论
Walter Roberson
Walter Roberson 2011-6-15
pointsize = 8;
scatter3(D_x(i)*ones(1,length(D_y{i})), D_y{i}, z{i}, pointsize, z{i});
Moes
Moes 2011-6-15
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!

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2011-6-15
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

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by