Info

This question is closed. Reopen it to edit or answer.

I got subscript indices must be real positive integers or logicals on my code

1 view (last 30 days)
Im trying to equalized my picture with this loop
for baris = 1 : jum_baris
for kolom = 1 : jum_kolom
Hasil(baris, kolom) = C(img(baris, kolom)); %this line got me that error
end
end
Hasil = uint8(Hasil);
  1 Comment
Tommy
Tommy on 5 Apr 2020
What is C? It is likely that
img(baris, kolom)
is the culprit. If C is a matrix, the above statement should return a real positive integer or logical.

Answers (2)

drummer
drummer on 5 Apr 2020
What is C?
I suppose your original image to be equalized is img. So is C any function applied in img?
If that's not the case, your just playing with the indexes.
Previously to your code, you can say the height and width of img.
[jum_baris, jum_kolon] = size(img);
That way, jum_baris and jum_kolom will be integers and positives. if you're taking them elsewhere, and they have decimal places, using them as indexes for matrix won't work.
yourNewMatrix(1.3, 1.12) % is not possible.
If they go randomly between positive and negative numbers, they won't work as well
yourMatrix(1,-2) % is not possible as well.
Cheers

Image Analyst
Image Analyst on 5 Apr 2020
This is a FAQ (possibly the most F or the error message questions), so see the FAQ:
It has a pretty thorough discussion.

Tags

Community Treasure Hunt

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

Start Hunting!