hi, I was wondering if someone can give me a hint how to create a multiple line graph where each line will be associated to certain Z line for example. I have data like attached where x is first column and so on.
So I want to have a 2D graph with x and y scatter points, and then through these points sometimes will pass a line that reflect a z column. Z column ranges between 16 and 145 m. It would be great if I can have lines at 15 35 55 75 95 115 135 155 m for example. Thanks a lot!
I have a scatter with but cant figure it out how i can plot lines at these intervals corresponding to Z values:
x=all(:,1);
y=all(:,2);
z=all(:,3);
pointsize = 10;
scatter(x, y, pointsize, z);

 채택된 답변

Star Strider
Star Strider 2017년 6월 23일

0 개 추천

See if this does what you want.
The Code
D = load('sensation scatter_test.txt');
[Du,~,ic] = unique(D(:,2)); % Unique Values — Second Column
xc = accumarray(ic, D(:,1), [], @(x) {cat(3,x)}); % Accumulate ‘x’ In 3D Matrix
yc = accumarray(ic, D(:,2), [], @(x) {cat(3,x)}); % Accumulate ‘y’ In 3D Matrix
zc = accumarray(ic, D(:,3), [], @(x) {cat(3,x)}); % Accumulate ‘z’ In 3D Matrix
figure(1)
for k1 = 1:size(xc,1)
plot3(xc{k1}, yc{k1}, zc{k1}) % Plot Each ‘(x,y,z)’ Separately On Same Axes
hold on
lgnd{k1} = sprintf('%6.2f',yc{k1}(1)); % Create Legend Entries
end
hold off
grid on
view([0 0]) % Rotate 3D Plot To 2D
legend(lgnd{:}, 'Location','SE')
The Plot

댓글 수: 6

sensation
sensation 2017년 6월 23일
Hi, Thanks a lot for this info. What I want is inreverse. X axis is ok, but second and third should be swapped.
On the Y axis values of 30 40 54 and 70 should be and lines values should correspond to the z column. These z values are a lot but I do not know if there is a chance to interpolate them and show for instance each 20th till the maximum what is 145 instead of all of them. Thanks a lot!!!
My pleasure.
I have no idea what you want. I do not understand your comment.
In the figure GUI, you can rotate the 3D plot. The view angles will be in the lower left corner of the GUI, labeled ‘Az’ and ‘El’.
See if this works for you:
figure(1)
for k1 = 1:size(xc,1)
plot3(xc{k1}, yc{k1}, zc{k1}, 'LineWidth',2) % Plot Each ‘(x,y,z)’ Separately On Same Axes
hold on
end
hold off
grid on
view([0 90]) % Rotate 3D Plot To 2D
xlabel('X')
ylabel('Y')
I have no idea what the legend entries would be in this, so I removed them.
Experiment to get the result you want.
Hi, I ve already explored the angles but it always gives the same X and Y but rotated.
In my example there is also pic attached. That is the graph I am willing to obtain, where x and y axis on the attached pic correspond to my first and second column, and curve with the number above, it's my third z column.
In the present solution proposed x and z are plotted and the curve is related to y. And it should be x and y in respect to z. I have tried this but it seems that it does not work well:
[Du,~,ic] = unique(D(:,3));
thanks!
Star Strider
Star Strider 2017년 6월 26일
My original Answer produces a plot similar to that in the image you attached. Other rotations of the 3D plot just produce straight horizontal or vertical lines.
I have no idea what you want. Your data do not have magnitudes similar to those in the image, and you have not said what variables (other than ‘x’, ‘y’, and ‘z’) any of the three columns represent. Your data are ‘gridded’ but not labeled.
I have done all I can. I will delete my Answer in a few hours.
sensation
sensation 2017년 6월 27일
Thanks a lot! I have added more data and magnitudes and works fine now. Cheers
Star Strider
Star Strider 2017년 6월 27일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2017년 6월 23일

댓글:

2017년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by