#### 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 208214 articles. 6 followers. lunamoonmoon (258) is leader.

4 Replies
316 Views

Similar Articles

[PageSpeed] 51
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 (8052)
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
Similar artilces about - how to sort out certain numbers in array:

MakeIndex sort
Hey all, I am running MiKTex on Windows XP, and am trying to sort entries numerically in my index. The entries are like this: 43-200, 55-300, 34-20, 90-220. They should be sorted by the number preceeding the hyphen and then by the number after the hyphen. Haven't been able to do this. Tried installing xindy for windows, didn't see to work. Thoughts? ...

Delete element from array control
Hi I'm using LV6i in my project and I've faced an apparent bug. Since it is an old version LV, I though it would be easy to find a thread related to it. However, after a not-so-quick search I found nothing (maybe wrong query terms). I'm going to pass the steps for those who'd like to replicate it. -create an array of numbers using the controls -calculate the size of this array -show the result with an indicator -everything inside a while loop Run the VI, insert three or four numeric values in the array control on the front panel. Check its size. Now, using the context menu f...

sorting in a matrix
Suppose I have a matrix say A = [1,2,3 ; 4,5,6 ; 7,8,9 ; 10,11,12] I want to sort its columns in descending order. Is it possible? "Samoline1 Linke" <maganatewoman@yahoo.com> wrote in message <hk64lm$peb$1@fred.mathworks.com>... > Suppose I have a matrix say A = [1,2,3 ; 4,5,6 ; 7,8,9 ; 10,11,12] > > I want to sort its columns in descending order. Is it possible? sort(A) See function "sort" in the help. ...

Matlab 7 1) mixing text with numbers 2) 2 line titles on plots
Hi All 1) Would someone remind me how I can mix text with numbers in an somthing that looks like an array. If I remember correctly Matlab produced a special type of funtion to handle this 2) Can someone tell me what the code is to create a 2 line title on a plot Thanks Harvey On Feb 28, 4:40 pm, "Harvey" <harveypoll...@talktalk.net> wrote: > Hi All > > 1) Would someone remind me how I can mix text with numbers in an > somthing that looks like an array. If I remember correctly Matlab > produced a special type of funtion to handle this > > 2) Can s...

qbasic number range #2
-> When using long integer variables I accidently found that numbers greater -> than the 2,147,xxx range listed in the help notes would work for printing -> and also GET instructions. For exaple -> x& = 5000 -> y& = x& * x& -> print "y& += "; y& -> will print the answer 25000000. -> What is going on. Thanks for any help. "Long" integers have a range from -(2^31) to +(2^31) - 1. That's roughly +/- 2 BILLION, not 2 million. dow ...

[OT..sort of]: IBM lifts global hiring forecast to 18,800
What's HP doing? --------------------------- Aug. 13, 2004. 01:00 AM IBM lifts global hiring forecast to 18,800 NEW YORK-International Business Machines Corp. will hire 8,800 more people this year than it had earlier expected, due in part to growth in its worldwide services business, the company said yesterday. IBM said it would take on 18,800 new employees globally in 2004, up from its previous forecast of 10,000 for this year in January. The company had later indicated to Reuters that its hiring could be as high as 15,000, one-third from universities and the rest experienced prof...

Sorting based on existence of keys
Hi experts Say I have an array @ks containing some strings which may or may not exist as keys in a hash %h. How do I sort @ks such that the non-existent keys come last (in any order), while the existing keys are sorted using, say, length($h{$a}) <=> length($h{$a}) (that is not really the property of the values I'll sort by, but that's not important). my @ks = qw(two three one four); my %h = ( one => 1, three => 333 ); for (sort { exists $h{$b} cmp exists $h{$a} || length $h{$a} <=> length $h{$b}} @ks) { print "$_\n" } This produces the in... sorting I use this script to retrieve all my .txt files in the current directory... Now the retrieved filenames all consist of a certain number followed by .txt, like 1.txt, 77.txt, 44.txt and so on.. Now is my question how do I sort these filenames in a correct way ? Since the sort function treats items as strings not as integers. Basicly I need to retrieve the highest number of the .txt files... opendir (homedir,".") || die("unable to open directory"); while (defined($filename=readdir(homedir))){ if ($filename=<*.txt>){print qq{$filename<br>};} } close...

sort order for strings of digits
I learn lots of useful things from the list, some not always welcome. No sooner had I found a solution to a minor inconvenience in my code, than a recent thread here drew my attention to the fact that it will not work for python 3. So suggestions please: TODO 2012-10-22: sort order numbers first then alphanumeric >>> n ('1', '10', '101', '3', '40', '31', '13', '2', '2000') >>> s ('a', 'ab', 'acd', 'bcd', '1a', 'a1', '222 bb', '...

siunitx: Division in numbers
Hello all, I'm looking at getting v1.1 of siunitx sorted out. One of the features that was suggested was recognition of division in numbers: \num{1/2} \num[numaddn=\pi]{\pi/2} I wonder what people thing such input should give as a result. It is easy to pass things through so that you get $1/2$, $\pi/2$ and so on. However, are other output results needed by users? -- Joseph Wright On Sep 22, 8:45=A0am, Joseph Wright <joseph.wri...@morningstar2.co.uk> wrote: > Hello all, > > I'm looking at getting v1.1 of siunitx sorted out. =A0One of the > features that was sugge...

Multiple ssh tunnels limited to certain users
Hello, in our public hospital we want to let external companies access the servers they have in maintenance. I would like to do this using a putty-ssh tunnel. The problem is that I want that every company can only connect to their server. With puttys plink the client tells the server where it should be redirected, e.g. plink -N -L 3390:winserver:3389 user@linuxserver. If I have only one ssh server running that autenticate all the users they can connect to all the servers because they pass the parameters to putty. Is it possible to configure sshd the way that user A can only ...

Re: What do you change to have a unique/numbered LOG/LST name? #9
Dear SAS-L; Thanks to all for input on unique Log/Lst names. I would have done the same as you've suggested with REXX or Script but a more automatic SAS solution is required. Here is what I was hoping to have as the required solution in a pseudo code, (not working) where the SAS program is written and a batch file is used to execute a SAS in batch which invokes your SAS program with the Log/Lst options. You then only need to copy the batch model YourSas.bat & change the SAS program name within it. Is it Ok to call SAS within a SAS in this way? If so, what is the best way to pass ...

Number of simultaneous connection
Hi all, I'm new with DB2 database, and working on AIX 5.2 with DB2 v8 Just a question regarding the similaneous connection. I'd like to know how many simultaneous connections that I have in a given time! Do you know how to get this information? Thanks for your help Doug cdngo@sopragroup.com wrote: > Hi all, > I'm new with DB2 database, and working on AIX 5.2 with DB2 v8 > Just a question regarding the similaneous connection. I'd like to know > how many simultaneous connections that I have in a given time! Do you > know how to get this informati...

How to share an array calculated in a one callback with another callback
Hello, I would like to know how I can share an array calculated in one callback function with another. I am very new to this GUIDE, so please show me the ways I can achieve this. Say I just have a button 'Simulate', a pop up button to choose between different value and an axes to display the result. Just to give you an idea function pushbutton1_Callback(hObject, eventdata, handles) t=0:.1:pi; sint=sind(t); cost=cosd(t); function popupmenu1_Callback(hObject, eventdata, handles) str = get(hObject, 'String'); val = get(hObject,'Value'); switch str{val}; ...

Sort is broken v6.2
When I try to sort my inbox by date I get a list that's mostly sorted but there are bunches of messages in the wrong place. Could this be because I have over ten thousand messages? The same thing happened on V5.0 so I moved up last month and the problem persists. Henry hjnoble@igc.org <hjnoble@igc.org> wrote in message news:1150837298.450606.283910@p79g2000cwp.googlegroups.com... > When I try to sort my inbox by date I get a list that's mostly sorted > but > there are bunches of messages in the wrong place. Could this be because > I have over ten...

Console Number Exception Handling.
I am attempting to use exception handling in the console to trap an invalid character into a numeric field. Unfortunately, using this example: ====================================================================== #include <exception> #include <iostream> using namespace std; int main(int argc, char *argv[]) { double number = 0; while (number <= 0) { std::cout << "Gimme a number: "; try { std::cin >> number; } catch (exception e) { std::cout << "Oops, you did it again."; } } } =============...

extracting numbers from arrays
Hey, I have a 128x104 array "SDM" with values that range from 1-100. I want to write a loop in MATLAB that extracts numbers from that array that have values between 20-30. Does anyone know how? Dina "Dina" <dandoun@uab.edu> wrote in message news:ef1d455.-1@webx.raydaftYaTP... > Hey, > > I have a 128x104 array "SDM" with values that range from 1-100. I > want to write a loop in MATLAB that extracts numbers from that array > that have values between 20-30. Does anyone know how? No loop needed; use logical indexing. A = 1+99*rand(128, 104)...

Sort-Problem
Hi, with the code below the output is sort by $verantw but$title and $file in the same row DON'T belong to$verantw. How do I have to make the sort command that $verantw,$title and $file in the row "belongs together"? Hope you understand my problem...... <?php$handle = opendir('.'); $daten = array();$daten['files'] = array(); $daten['title_tags'] = array();$daten['verantw'] = array(); while ($file = readdir($handle)) { if (substr($file, -4) == '.htm') {$daten['...

Group Message Don't Send to Certain Senders
FYI - Lotus Notes 5.08 server and clients. When I send a message to a group using certain user ids the message goes to everyone in the group except the sender, who is also a member of the group. If someone else sends to the group they get the message. I tried using the problematic user id on a profile of a user that always receives messages when they send and had the same result...they don't receive the message. No one has any groups in their local address book and the log.nsf on the server simply confirms that the message goes to everyone in the group except the sender. Not s...

Sorting: 1 to 99
CLS REM ============================================================ REM To SORT any numbers 1 to 99; but no repeats. REM (This compares sort-numbers with Nos.1 to 99, REM and not with each other.) REM [You can't put a comment at end of DATA line, or it is REM regarded as data, by QBasic.] REM ============================================================ DIM a(1 TO 99), b(1 TO 99), c(1 TO 99) 'All ranges must be 99 PRINT "======= Store data in array ============================" N = 7 FOR X = 1 TO N READ a(X) PRINT a(X); NEXT X PRINT ...

Array aliases wih hashes, some questions
Hi, docs say, that when passing an array to a sub, the elements of @_ in the sub are aliases for th elements of the actual array. So, as long no other array or new list is assigned to @_, assigning a value to $_[0],$_[1], ... will change the elements in the array passed as argument. I tried how this will behave when passing a hash instead of an array: use warnings; %hash = (a => 1, b=> 2); test(%hash); print %hash; sub test { $_[0] = 3;$_[1] = 4; $_[2] = 5;$_[3] = 6; } This will print out "a4b6". In other words, the array elements which correspond to the keys of th...

Re: A variable Sorting Problem #7
On Fri, 27 Jul 2007 06:55:44 -0000, nichas <sachin.gadkar@GMAIL.COM> wrote: > >data one; >input b d c a e; >datalines; >1 2 3 4 5 >3 4 3 2 1 >; >run; >proc sql; >select name >into :mvar separated by ' ' >from dictionary.columns >where libname='WORK' and memname='ONE' >order by name; >quit; >%put &mvar.; >data one; >retain &mvar.; >set one; >run; Nothing quite like jumping in late, reposting what's already said? Please read the thread prior to posting. That way, people don't have to re...

Unix Sort?
Hi, I have a file and I want to extract all the lines that start with a number or letter, then sort those results, eliminating duplicates, and place them in an output file. I seem to have all the right parts, but cannot get them to work together: cat input.txt | grep '^[0-9][a-z][A-Z]' | sort -u > output.txt Any help? Thanks! 2007-02-21, 11:26(-08), amerar@iwc.net: > Hi, > > I have a file and I want to extract all the lines that start with a > number or letter, then sort those results, eliminating duplicates, and > place them in an output file. > > I seem...

Sorting
Is there a way in Pegasus to filter/search on either a flag or a colour. I have a number of emails some of which require action at some point in the future. What I'd like to do is file these emails in their respective folders and then do a search across all folders to find the flagged emails. Thanks Colin Colin a �crit : > Is there a way in Pegasus to filter/search on either a flag or a > colour. I have a number of emails some of which require action at some > point in the future. What I'd like to do is file these emails in their > respective folders and then ...

Sorting files recursively
Hi everyone, I would like to sort all files in a directory tree by modification time. I have tried ls -ltR', but with that command the files are only sorted within each directory; I want a global sort. Any ideas? Regards, August On 3 Oct 2006 02:35:52 -0700, augukarl@yahoo.se wrote: > Hi everyone, > > I would like to sort all files in a directory tree by modification > time. I have tried ls -ltR', but with that command the files are only > sorted within each directory; I want a global sort. Any ideas? [...] ls -ltd -- **/* (assuming your shell is zsh (or a rece...