필터 지우기
필터 지우기

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