I have a matrix a=[1 2 3 4] in my workspace, how can i plot it in the format a[x1 y1 x2 y2]. So that (x1y1) and (x1y2) forms a line.

 採用された回答

Guillaume
Guillaume 2016 年 1 月 27 日

0 投票

plot(a(1:2:end), a(2:2:end))
is one way to do it.
But what you should do really is reshape a in x and and y rows:
a = reshape(a, 2, []);
plot(a(:, 1), a(:, 2));

1 件のコメント

Himanshu Tomar
Himanshu Tomar 2016 年 1 月 27 日
thanxalot Guillaume.. it worked

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 1 月 27 日

0 投票

x1 = a(1);
x2 = a(3);
y1 = a(2);
y2 = a(4);
plot([x1, x2], [y1, y2]);
This is not the best way, but you appear to be having difficulty with the better ways.
By the way, we are still waiting for you to post the additional information requested in your earlier question on this topic.

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by