for loop, indexing issues, and graph conversion to binary matrix

Hey i'm required replicating the following image in matlab through the use of matrices and the command 'imshow'. It needs to be a matrix of 501x 501, i started of with creating a zero matrix through the command (zeros(501)). Then added sections to it. I ended up getting the cirle in to the matrix but i cant work out away to get the curves in. The equation for the curve is x = [-250:250]; y = x.^3 / 62500;. I have tried to achieve this through the following command where extH being the matrix, without the circle because im trying to focus on the curve.
extH= zeros(501);
for x = [-250:250];
y = x.^3 / 62500;
extH(1:501, y)=1;
end
imshow(extH)
This did not work as it displayed the following message 'Subscript indices must either be real positive integers or logicals'. If anyone know how to solve this issue or know a better way to achieve this image please help.

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 3 月 27 日

0 投票

% This is correct
extH= zeros(501);
x = -250:250;
y = x.^3 / 62500;
The problem is this line
extH(1:501,y)=1;
y is used as index, but it should be a positive integer

1 件のコメント

Michael Brady
Michael Brady 2016 年 3 月 27 日
How would you go about in getting this curve on the zero matrix of 501 then because i have tried various other solutions but they all ended in failure.

この質問は閉じられています。

質問済み:

2016 年 3 月 27 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by