surface plot of cell arrays

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일

0 개 추천

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

Moes
Moes 2011년 6월 15일
One way to plot the second piece of code is to use:
figure;
hold on;
for i = 1 : divs_x,
plot3(D_x(i)*ones(1,length(D_y{i})), D_y{i}, z{i});
end;
but this does not do color coded value of function z.
Walter Roberson
Walter Roberson 2011년 6월 15일
I had misunderstood, I think. I thought that your surface was defined over a rectangle but you wanted that tiled irregularly. But it appears that instead your surface is not defined over a rectangle ?
If you initialize a rectangular array with either NaN or inf, then you can fill in just the parts that are defined. surf() will interpret NaN or inf as meaning not to plot anything. For technical reasons, inf is faster to work with than NaN is.
Moes
Moes 2011년 6월 15일
Ah excellent! I'll give it a try.
Moes
Moes 2011년 6월 15일
I tried the following code, but it does not produce the correct result:
divs_x = 10;
D_x = linspace(1, divs_x, divs_x);
z = inf(divs_x, 5*max(D_x));
D_y = inf(divs_x, 5*max(D_x));
for k = 1 : divs_x,
divs_y = 5*D_x(k);
D_y(k,1:divs_y) = linspace(0, pi, divs_y);
z(k,1:divs_y) = cos(D_y(k,1:divs_y));
end;
figure;
surf(D_y(end,:), D_x, z)
The following code produces the right graph but I do not know how to apply a color map to it:
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;
figure;
hold on;
for i = 1 : divs_x,
scatter3(D_x(i)*ones(1,length(D_y{i})), D_y{i}, z{i});
end;
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일

1 개 추천

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

카테고리

질문:

2011년 6월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by