surface plot of cell arrays

조회 수: 8 (최근 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