Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Subscript indices must either be real positive integers error? Can't figure out why

조회 수: 1 (최근 30일)
Ryan Kubik
Ryan Kubik 2016년 6월 14일
마감: MATLAB Answer Bot 2021년 8월 20일
I am trying to analyze a BW image,
[l w]=size(S4);
for i=1:w
y=(Y(1)+((Slope)*(i)));
h(i)=sum(S4(i,[0:y]));
end
Does anyone know what is wrong with my code? S4 is a 780x4608 matrix, Slope is an integer,
  댓글 수: 1
Adam
Adam 2016년 6월 14일
편집: Adam 2016년 6월 14일
This line could evaluate to anything, from the information you have given:
y=(Y(1)+((Slope)*(i)));
Certainly there is no guarantee that it will provide a valid index into S4.

답변 (2개)

Moe_2015
Moe_2015 2016년 6월 14일
편집: Moe_2015 2016년 6월 14일
It is because of this line:
h(i)=sum(S4(i,[0:y]));
You cannot access column 0 of a matrix in MATLAB. MATLAB indices start from 1.
  댓글 수: 2
Ryan Kubik
Ryan Kubik 2016년 6월 14일
Interesting! Now that I fixed that, I get an error that "Index exceeds matrix dimensions" Yet it seems all my dimensions are in order. Wanna try to go 2/2?!
Moe_2015
Moe_2015 2016년 6월 14일
편집: Moe_2015 2016년 6월 14일
One thing I see right off the bat is you define i=1:w (so this is 1:4608). However in:
h(i)=sum(S4(i,[0:y]));
You are using i to loop through the rows of S4. S4 only has 780 rows not 4608 (the number of columns). I don't know what you are trying to accomplish here but you need to put i in your column index if you want the dimension to not error out. Alternatively, maybe what you want to do is define i=1:l. Again, I don't know what you are trying to accomplish here so try either one based on what you need.
Also, take a look at what Adam commented on your question. I don't know the values of Y(1) or Slope*i but that may also cause problems getting a value of y that is greater than the number of columns you have in S4. However, I do not know for sure and maybe your numbers work out but in any case, the way you have the code set up, "i" is causing the problem above.

Image Analyst
Image Analyst 2016년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by