Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to get all selected values in one variable

Subject: how to get all selected values in one variable

From: sathish kumar

Date: 3 Jan, 2013 04:32:13

Message: 1 of 3

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

Subject: how to get all selected values in one variable

From: Nasser M. Abbasi

Date: 3 Jan, 2013 05:07:41

Message: 2 of 3

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

Subject: how to get all selected values in one variable

From: sathish kumar

Date: 3 Jan, 2013 11:36:08

Message: 3 of 3

"Nasser M. Abbasi" wrote in message <kc33mu$qfe$1@speranza.aioe.org>...
> 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
>
> thank u sir
but i got it like this
now its working ,code is here
t=1;k=[];g=[];
> > for i=1:length(set)
> > if (final >= t(i)&& edge >= h(i))
> > selected = i;
> > g = [selected]
                           k(t)=g;
                               t=t+1
> > end
            end
   thank u for u help


> >

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us