# MATLAB Subscript indices must either be real positive integers or logicals

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

store_y_temp=real(Y(Y>Iy));
store_z_temp=Z(store_y_temp);


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);


or

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...).

Example:

  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 =
5
8

• @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. 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.

• i need to study numeric types better. thanks @Sidhha 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.