I'm a beginner of this program. Please help me to do the plot like figure 2 My editor note: scatter(x1,y1,z1,"filled",'*'); hold on

 採用された回答

Star Strider
Star Strider 2022 年 1 月 12 日

1 投票

Try this —
x1 = randn(10,1); % Column Vectors
y1 = randn(size(x1));
z1 = randn(size(x1));
figure
scatter3(x1, y1, z1, 'filled')
grid on
zv = zeros(size(x1));
figure
scatter3(x1, y1, z1, 'filled')
hold on
plot3([zv x1]', [zv y1]', [zv z1]')
scatter3(0, 0, 0, 150, 'g', 'p', 'filled')
hold off
grid on
.

4 件のコメント

Beginner Boy
Beginner Boy 2022 年 1 月 13 日
編集済み: Beginner Boy 2022 年 1 月 18 日
Thank you very much!
the results show like this
What did I do wrong?
Star Strider
Star Strider 2022 年 1 月 13 日
My pleasure!
My guess is that the vectors in the code image began as row vectors, not column vectors, as were the vectors in my code.
Changing my code from column vectors to row vectors provides a solution —
x1 = randn(1,10); % Row Vectors
y1 = randn(size(x1));
z1 = randn(size(x1));
figure
scatter3(x1, y1, z1, 'filled')
grid on
zv = zeros(size(x1));
figure
scatter3(x1, y1, z1, 'filled')
hold on
plot3([zv; x1], [zv; y1], [zv; z1])
scatter3(0, 0, 0, 150, 'g', 'p', 'filled')
hold off
grid on
The main difference is how the vectors are concatenated in the plot3 call that draws the lines, since plot3 has to see them the same way, regardless.
If your vectors are column vectors, use my original code.
If your vectors are row vectors, use the code in this comment.
(In both, plotting the origin as a green pentagram (or anything else) is optional. I did it here simply for clarity.)
.
Beginner Boy
Beginner Boy 2022 年 1 月 14 日
It's work!
Thanks again for your help!
Star Strider
Star Strider 2022 年 1 月 14 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2021b

タグ

質問済み:

2022 年 1 月 12 日

編集済み:

2023 年 9 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by