How to replace values in specific lines and on determined conditions
4 views (last 30 days)
Show older comments
Breylla Carvalho
on 7 Jul 2017
Answered: MD TAUSIF AKRAM
on 1 Aug 2019
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!!! :)
0 Comments
Accepted Answer
James Tursa
on 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;
More Answers (2)
Walter Roberson
on 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.
0 Comments
MD TAUSIF AKRAM
on 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.
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!