I have a 2D boolean array stored 0s and 1s where I want to plot a red pixel. For example, If the 2D boolean array has 1 for (20, 20) location, it should plot a red pixel at that location. Else, it is has 0, it should not plot the red pixel.
Can someone help me?

1 件のコメント

Radhika Kulkarni
Radhika Kulkarni 2019 年 11 月 30 日
2D Boolean Array is size 101x101

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

 採用された回答

Stephan
Stephan 2019 年 11 月 30 日

0 投票

% your array
A = randi(2,101)-1;
% the result;
R=255*ones(101);
G=255*(-A+1);
B=255*(-A+1);
res = cat(3,R,G,B);
% plot result
imshow(res)

4 件のコメント

Radhika Kulkarni
Radhika Kulkarni 2019 年 11 月 30 日
shouldn't there be a loop to check each location of 2D Boolean array?
Stephan
Stephan 2019 年 11 月 30 日
No need for a loop - this is vectorized code.
Radhika Kulkarni
Radhika Kulkarni 2019 年 11 月 30 日
編集済み: Radhika Kulkarni 2019 年 11 月 30 日
Great! It worked.
Now, It is plotting my image from the array. I need to rotate the axes by 135 deg CCW. How do I do that?
See the attachment. I need to rotate this by 135 deg CCW.
Stephan
Stephan 2019 年 11 月 30 日
編集済み: Stephan 2019 年 11 月 30 日
If you have Image Processing Toolbox use imrotate. If not see FEX to download a tool.

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

その他の回答 (2 件)

Radhika Kulkarni
Radhika Kulkarni 2019 年 11 月 30 日

0 投票

One more thing, I need to put this in a some time refresh loop, so it grows in size and back to normal size. Like pumping heart.

1 件のコメント

Stephan
Stephan 2019 年 11 月 30 日
On File Exchange there are also tools to create gif animations. Maybe you want to use this.

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

Radhika Kulkarni
Radhika Kulkarni 2019 年 12 月 2 日

0 投票

How can I also show the x & y axis and ticks and axis data points to plot along with this vectorized code?

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

質問済み:

2019 年 11 月 30 日

回答済み:

2019 年 12 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by