X-Received: by 10.180.78.36 with SMTP id y4mr12600978wiw.1.1357189663998;
        Wed, 02 Jan 2013 21:07:43 -0800 (PST)
Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!m1no13951508wiv.0!news-out.google.com!l12ni280602wiv.1!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to get all selected values in one variable
Date: Wed, 02 Jan 2013 23:07:41 -0600
Organization: Aioe.org NNTP Server
Lines: 59
Message-ID: <kc33mu$qfe$1@speranza.aioe.org>
References: <kc31kd$p4m$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: 2CibzTqnux2ggoH9QofcGw.user.speranza.aioe.org
Mime-Version: 1.0
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
X-Notice: Filtered by postfilter v. 0.8.2
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Xref: news.mathworks.com comp.soft-sys.matlab:785825

On 1/2/2013 10:32 PM, sathish kumar wrote:
> good morning to all
> here i am getting only last value i.e selected but not the previously selected values
> please tell me how to buffer previous selected values
> her is my code
> g=[];
> for i=1:length(set)
>      if (final >= t(i)&& edge >= h(i))
>                   selected = i;
>                 g = [selected]
>                           end
> end
> in this  selected values are 4,5
> in the command window it is displaying
> g=4
> g=5
> but i want to get   g= 4 5
> how to get prevoius value with newly selected value like g= 4 5
> please tell me
>

the problem: collect values based on condition into a vector.
One day to do this, is to allocate the maximum possible size
of values that can be collected, and in the loop add them
to this vector using different index.

At the end of the loop, you truncate the vector to the size
actually collected.

Example:

-------------------
N       = 10;
the_set = rand(N,1);
g       = zeros(N,1);

k = 0;

for i = 1:N
     if the_set(i)<0.5
        k    = k+1;
        g(k) = the_set(i);
     end
end

g = g(1:k)
--------------------

Or, if your data structure allows this, you can simply do it
in one command using logical indexing

-----------------------------
g = the_set(the_set<.5)
-----------------------------

--Nasser