Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Nested For loop issue...
Replies: 4   Last Post: Feb 21, 2013 4:24 PM

 Messages: [ Previous | Next ]
 BILAL USMANI Posts: 3 Registered: 6/8/12
Nested For loop issue...
Posted: Feb 20, 2013 12:39 PM

Hello
I am generating values of Itot from a while loop in which Itot is of different length in every iteration. MATLAB retains the order of the matrix Itot so every row contains zeros , except the largest. I am using this code to find the total number of elements in each row of Itot. cItot returns the value as a row vector.

for i=1:size(Itot,1)
for c1=size(Itot,2):-1:1;
if Itot(i,c1)~=0
cItot(i,1)=c1;
break;
end
end
end
----------
But this is highly inefficient, espicially when I have the order of Itot as 1000 by 24523210. Is there an efficient way to do this?

Date Subject Author
2/20/13 BILAL USMANI
2/20/13 dpb
2/21/13 BILAL USMANI
2/21/13 dpb
2/21/13 Bruno Luong