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
Re: Nested For loop issue...
Posted: Feb 21, 2013 9:59 AM

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

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