From: forkandwait w on 21 Feb 2010 14:06 Hi all, Are there any advanced logical operators, especially for the effect of "in" and "between"? I would like to write the following iages = find (ages == 0 | ages == 1 | (ages >=20 & ages <=30) | ages == 65); as iages = find (ages INOP [0 1 65] | ages BETWEENOP [20 30]) or some such. I would also happily use a function, along the lines of in(X, Y) or whatever. Advice? Maybe I am out of luck? Maybe I shouldn't have such a syntactic sweet tooth?...
From: michael scheinfeild on 21 Feb 2010 14:23 "forkandwait w" <forkandwait(a)gmail.com> wrote in message <hls06s$411$1(a)fred.mathworks.com>... > Hi all, > > Are there any advanced logical operators, especially for the effect of "in" and > "between"? > > I would like to write the following > > iages = find (ages == 0 | ages == 1 | (ages >=20 & ages <=30) | ages == 65); > > as > > iages = find (ages INOP [0 1 65] | ages BETWEENOP [20 30]) > > or some such. > > I would also happily use a function, along the lines of in(X, Y) or whatever. > > Advice? Maybe I am out of luck? Maybe I shouldn't have such a syntactic sweet tooth?... why you need this? and | is || maybe try to write your function ...
From: Oleg Komarov on 21 Feb 2010 14:36 "forkandwait w" > Hi all, > > Are there any advanced logical operators, especially for the effect of "in" and > "between"? > > I would like to write the following > > iages = find (ages == 0 | ages == 1 | (ages >=20 & ages <=30) | ages == 65); > > as > > iages = find (ages INOP [0 1 65] | ages BETWEENOP [20 30]) > > or some such. > > I would also happily use a function, along the lines of in(X, Y) or whatever. > > Advice? Maybe I am out of luck? Maybe I shouldn't have such a syntactic sweet tooth?... Let's say ages is: ages = [0:100]; IDX = ismember(ages, [0 1 20:30 65]); I wouldn't use find if not striclty necessary. (You can always count how many ages meet the condition by nnz(IDX) and extract them with ages(IDX)). Also | and || are not the same. Short circuit operators don't work on non scalars. Oleg
From: forkandwait w on 21 Feb 2010 15:28 > Let's say ages is: > ages = [0:100]; > IDX = ismember(ages, [0 1 20:30 65]); Using ismember() worked great. One of my main reasons for wanting this was to store the ages of interest only once and then reuse them for indexing, legends, etc. Here is my code: % history of log mortality rates by interesting age intages = [0 1 5 30 50 65 85]; IDX = ismember(ages, intages); plot(years, mx_sql(IDX,:)); legend (num2str (intages'));
|
Pages: 1 Prev: fft and ifft : and fftshift Next: How to generate ROC Curve for SVMs?? |