Is there a way to change a vector range by condition?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
maxmathlab
am 12 Okt. 2016
Bearbeitet: Andrei Bobrov
am 12 Okt. 2016
Hallo,
i use a simple example for my problem:
i have a vector
x=[-10:10];
x=x';
Now i want to change values of the range 5:15 which are positive. i tried something like this:
x(5:15 & x>0,1)=100
x( (5:15) & (x>0) ,1)=100
x(5:15,1)&x>0=100
x(x(5:15)<0,1)=100
nothing seems to work. pls help.
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 12 Okt. 2016
Bearbeitet: Andrei Bobrov
am 12 Okt. 2016
x=(-10:10)';
z = x(5:15);
z(z>0) = 100;
x(5:15) = z;
or
x=(-10:10)';
b = false(size(x));
b(5:15) = true;
x(b & x > 0) = 100;
or in one row
x(intersect(find(x>0),5:15)) = 100;
Weitere Antworten (1)
KSSV
am 12 Okt. 2016
If you want to change values at known indices use:
x(5:15)=100;
If you want to change values according to the values of x use:
x(x>1)=100;
x(x>1 & x<2)=100;
1 Kommentar
Siehe auch
Kategorien
Mehr zu Multirate and Multistage Filters finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!