Drawing line between elements with same values in a 2D matrix

Hello community! I have a 2d Matrix:
A = [1 2 3 4 5 6;1 3 5 4 6 9;4 1 3 8 7 5];
it looks then like
1 2 3 4 5 6
1 3 5 4 6 9
4 1 3 8 7 5
Now I want to draw lines between elements with value = 1 and value = 3 and mark these values on the line.
Besides, in the plot, the columns of the matrix should be labeled in form of a x axis by
x = 8:13;
and the rows of the matrix should be labeled in form of a y axis by
y= 2:0.1:2.2;
Can someone please help me on this? Thanks a lot!

回答 (1 件)

Joseph Cheng
Joseph Cheng 2015 年 9 月 15 日

0 投票

clf
A = [1 2 3 4 5 6;1 3 5 4 6 9;4 1 3 8 7 5];
y = 2:0.1:2.2;
x = 8:13;
[X Y] = meshgrid(x,y);
[oI]= find(A==1);
[tI]= find(A==3);
figure(1),hold on
plot(X(oI),Y(oI),'rx')
plot(X(tI),Y(tI),'bx')
%gen lines
for ind = 1:length(oI)
for jind = 1:length(tI)
plot([X(oI(ind)) X(tI(jind))],[Y(oI(ind)) Y(tI(jind))],'g')
end
end

2 件のコメント

James Lorringer
James Lorringer 2015 年 9 月 15 日
Thanks, but this is what I got
Could you please may be do some modifications?
Joseph Cheng
Joseph Cheng 2015 年 9 月 15 日
shouldn't you be doing the modifications? Based on your description that's what you described. You'll have to put in some effort.

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

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2015 年 9 月 15 日

コメント済み:

2015 年 9 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by