How to replace values in specific lines and on determined conditions

4 次查看(过去 30 天)
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!!! :)

采纳的回答

James Tursa
James Tursa 2017-7-7
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;

更多回答(2 个)

Walter Roberson
Walter Roberson 2017-7-7
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 2019-8-1
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.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by