Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
BILAL USMANI

Posts: 3
Registered: 6/8/12
Nested For loop issue...
Posted: Feb 20, 2013 12:39 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.