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
Re: Nested For loop issue...
Posted: Feb 21, 2013 9:59 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <none@non.net> wrote in message <kg33i6$vam$1@speranza.aioe.org>...
> On 2/20/2013 11:39 AM, BILAL USMANI wrote:
> > 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?

>
> Not sure what your end object is; knowing that would undoubtedly aid in
> specific responses, but--it sounds as though Itot might be a good place
> for a cell array instead of a "standard" base array--a cell array can
> have differing vector sizes in each element.
>
> But for any array, the number of elements that aren't zero in a column
> can be determined from
>
> sum(x~=0,2)
>
> --

OK..
Now Itot comes from a while loop. and the starting value or the middle values can be zero. In every iteration, Itot have different vector length, but to retain the order matlab fill zeros. I want to count till the last non-zero element of the Itot in evey iteration. The variable c1 in my loop is doing that. if I use the suggested logic. My middle zero values will be excluded.
Thanks



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.