Filter löschen
Filter löschen

How to replace values in specific lines and on determined conditions

4 Ansichten (letzte 30 Tage)
I'm in trouble: I have a dataset with 128597 lines and 10 columns. I need to change the values from column 10 between line 10276 until 128597.
And this change have to respect some conditions, like: If the value is between 11 and 33, the value will become 1 If the value is between 34 and 56, the value will become 5 And go on...
I tried the code below, but didn't work:
m(10276:128597,10) > 11 & m(10276:128597,10)< 33=1;
Can anyone help me please!!! :)

Akzeptierte Antwort

James Tursa
James Tursa am 7 Jul. 2017
Something like this?
v = m(10276:128597,10);
v( v > 11 & v < 33 ) = 1;
v( v > 34 & v < 56 ) = 5;
:
m(10276:128597,10) = v;

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 7 Jul. 2017
r1 = 10276; r2 = 128597;
row_select = (1 : r2).' >= r1;
mask = row_select & m(:,10) > 11 & m(:,10) < 33;
m(mask,10) = 1;
mask = row_select & m(:,10) > 34 & m(:,10) < 56;
m(mask,10) = 5;
Please re-check what you want done if the value is exactly 11, or exactly 33; or if the value is exactly 34 or exactly 56, or if the value is between 33 and 34.

MD TAUSIF AKRAM
MD TAUSIF AKRAM am 1 Aug. 2019
How to replace the old values in array with new values in array.
oldu(:,1)=BY_U(:,1)
oldu =
0.0087
0.0353
-0.0709
0.1233
0.2092
-0.0225
0.2878
-0.0522
0.1046
-0.0018
0.0010
newu(:,1)=KY(:,1)
newu =
0.0087
0.0353
-0.0709
0.1233
0.2092
-0.0225
0.2878
-0.0522
0.1046
-0.0018
0.0010
After every iteration my new value chnges. So, I want to change the old values with new one. Please help me out. Thanks in advance.

Kategorien

Mehr zu Line Plots 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!

Translated by