Array indices must be positive integers or logical values.

A = imread('boat.png');
A=double(A);
[row,col]=size(A);
h=zeros(1,300);
for x=1:1:row
for y=1:1:col
t=A(x,y);
% disp(t)
h(t)=h(t)+1;
end
end
subplot(2,1,1)
imshow(uint8(A))
title('Original Image')
subplot(2,1,2)
bar(h)
title('Histogram of the Image')

 採用された回答

the cyclist
the cyclist 2021 年 4 月 13 日
編集済み: the cyclist 2021 年 4 月 13 日

0 投票

Your variable A is the image data.
Your variable t is the value of the image data at the (x,y) coordinate. That value of t could be equal to zero sometimes. If t==0, then this line of code
h(t)=h(t)+1;
will be equivalent to
h(0)=h(0)+1;
so you are trying to write to the "zeroth element" of the array h, which is nonexistent (and triggers the error).

6 件のコメント

Prashant Saini
Prashant Saini 2021 年 4 月 13 日
can you please fix this error....i didn't understand what are you saying?
the cyclist
the cyclist 2021 年 4 月 13 日
I don't know what your code is supposed to do, so I cannot fix it.
I suggest that you write a short paragraph explaining the purpose of the code. Then, fully comment your code, explaining what each line is supposed to do.
Prashant Saini
Prashant Saini 2021 年 4 月 13 日
Write a Matlabcode to calculate histogram of theimage without using library function imhist ( ).
the cyclist
the cyclist 2021 年 4 月 13 日
To be clear, we are not here to do your homework for you.
If you do the things I suggest, I will try to help you learn how to do your homework.
Prashant Saini
Prashant Saini 2021 年 4 月 13 日
sorry sorry i want to fix error only
madhan ravi
madhan ravi 2021 年 4 月 13 日
編集済み: madhan ravi 2021 年 4 月 13 日
Well, you didn't follow cyclists comments. Calculate the unique pixels sum and then use the bar function.

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

その他の回答 (0 件)

カテゴリ

質問済み:

2021 年 4 月 13 日

編集済み:

2021 年 4 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by