I have a n x 3 double containing x, y and z coordinates. Can someone tell me where did I go wrong?


Error: Subscript indices must either be real positive integers or logicals.


I am suggesting you are doing something like

Find the points such that the $y$-coordinate of this $n\times 3$ array is greater than some $Iy$, then find these points' $z$-coordinates.

You have several ways to do this.

Most simple command would be (if we assume the same row corresponds to the same point):

z_temp = z(y>Iy);


z_temp = z(find(y>Iy));

y>Iy is a logical vector returning 1 in the entry if the criterion is met, 0 otherwise. find finds the non-zero entry's index. The first one is faster though (if you use the second one while writing scripts, mlint will remind you the first method is better...).


  x = [1; 2; 3; 4];
  y = [1/2; -1/2; -3/2; 3/2];
  z = [5; 6; 7; 8];

Typing the first command results:

>> z_temp = z(y>0)
   z_temp = 
  • $\begingroup$ @newbee No problem, welcome to this site. I have several suggestions. Your question is kinda short, and sounds like a debugging type of question, it may draw downvotes from other users. Next time when asking, you may wanna state the background where this question arises, what is the goal of writing these script, etc. $\endgroup$
    – Shuhao Cao
    Jul 25 '13 at 3:23

The reason you get the error is because store_y_temp is not an integer and you are using it to refer to array indices. Check a similar question.

  • $\begingroup$ i need to study numeric types better. thanks @Sidhha $\endgroup$
    – newbee
    Jul 25 '13 at 3:22

a=imread('3.jpg'); a1=zeros(size(a)); for i=1:size(a,1) for j=1:size(a,2) for k=1:3 if((a((i-1),j,k)>=a(i,j,k) && a(i,j,k)>=a((i+1),j,k)) ||(a((i-1),j,k)>=a(i,j,k)&& a(i,j,k)>=a((i+1),j,k))||(a(i,(j-1),k)>=a(i,j,k)&& a(i,j,k)>=a(i,(j+1),k))|| (a(i,(j-1),k)<=a(i,j,k)&& a(i,j,k)<=a(i,(j+1),k))|| (a((i+1),(j+1),k)>=a(i,j,k)&&a(i,j,k)>=a((i-1),(j+1),k))|| (a((i+1),(j+1),k)<=a(i,j,k)&&a(i,j,k)<=a((i-1),(j+1),k))|| (a((i-1),(j-1),k)>=a(i,j,k)&& a(i,j,k)>=a((i+1),(j+1),k))|| (a((i-1),(j-1),k)<=a(i,j,k)&& a(i,j,k)<=a((i+1),(j+1),k))) a1(i,j,k)=round(a(i,j,k)); else a1(i,j,k)=round((a((i-1),(j-1),k)+a((i-1),j,k)+a((i-1),(j+1),k)+a(i,(j-1),k)+a(i,(j+1),k)+a((i+1),(j-1),k)+a((i+1),j,k)+a((i+1),(j+1),k))/8); end end end end ??? Subscript indices must either be real positive integers or logicals.

please help me

  • $\begingroup$ You should ask your question separately $\endgroup$
    – Ömer
    Sep 14 '15 at 9:27
  • 3
    $\begingroup$ Welcome to SciComp! As Ömer points out, you should ask your question separately. However, you are more likely to get help about a MATLAB syntax question on MATLAB's forums. Also, as currently stated, your question will be closed if you ask it, due to the lack of any background/explanation and lack of formatting in your question. If you choose to post your question, please revise it to include what you have tried and what you are trying to do, and please also format the code so it is easier to read. $\endgroup$ Sep 14 '15 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.