f



how to sort out certain numbers in array

Hi,
I've got simple question,
how to get rid of some numbers I don't want in my array ?
For example,
I have a vector A(50,1) with values in ascending order from 1000 to
2500. What to do if I want to remove all values larger then 1755 and
create another vector ?
Thanks
0
t.slowik (5)
11/29/2006 11:45:47 PM
comp.soft-sys.matlab 210211 articles. 11 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
428 Views

Similar Articles

[PageSpeed] 53

Tom:
<SNIP yet another mat-prune evergreen...

> What to do if I want to remove all values larger then...

one of the many solutions

% the big
     b=1:10
% the small
     s=b(b<=5)

us
0
us1 (8051)
11/30/2006 12:12:23 AM
Ok, but how to do it in loop ?
I have something like that :
for i=1:50
   for n = 1:251
        f1(n) = (some expression with (i) )
        f2(n) = (some expression with (i) )
        f3(n) = (some expression with (i) )
        f4(n) = (some expression with (i) )
and I want to save only values :
f1 <= 150;
f2 >= -2400;
f3 <= 450;
f4 >= -2700;

- how ?
0
t.slowik (5)
11/30/2006 3:45:47 AM
Tom wrote:
>
>
> Ok, but how to do it in loop ?
> I have something like that :
> for i=1:50
> for n = 1:251
> f1(n) = (some expression with (i) )
> f2(n) = (some expression with (i) )
> f3(n) = (some expression with (i) )
> f4(n) = (some expression with (i) )
> and I want to save only values :
> f1 <= 150;
> f2 >= -2400;
> f3 <= 450;
> f4 >= -2700;
>
> - how ?
How about something like this? (not sure if this is what you mean)

indices=find(f1<=150);
f1=f1(indices);
0
mmilman (1)
11/30/2006 7:55:12 AM
Why do it in the loop?  Matlab is much more efficient when using
logical indexing (which has made find() pretty irrelevent):
f1 = f1(f1<=150);
or f1(f1<=150) = [];
Both of these presume that f1 is a vector.  if f1 is a matrix, you need
to to either reshape to a vector or use a magic value (0, nan, -99999,
whatever's appropriate to the data) to indicate what's not wanted.

if you _have_ to do it in the loop, then you need another loop
variable, one for each f1, like this:

j = 1;
k = 1;
....
> for i=1:50
>    for n = 1:251
>         f1(j) = (some expression with (i) )
% if this value doesn't meet the criteria for keeping, j will not be
incremented, and will be overwritten next loop
           if fi(j) <= 150; j = j+1; end;
>         f2(k) = (some expression with (i) )
Same for f2, etc.
>         f3(n) = (some expression with (i) )
>         f4(n) = (some expression with (i) )

Marc

On Nov 29, 9:45 pm, Tom <t.slo...@yahoo.com> wrote:
> Ok, but how to do it in loop ?
> I have something like that :
> for i=1:50
>    for n = 1:251
>         f1(n) = (some expression with (i) )
>         f2(n) = (some expression with (i) )
>         f3(n) = (some expression with (i) )
>         f4(n) = (some expression with (i) )
> and I want to save only values :
> f1 <= 150;
> f2 >= -2400;
> f3 <= 450;
> f4 >= -2700;
> 
> - how ?

0
amarcpassy (19)
11/30/2006 2:46:25 PM
Reply: