replace values by the previous value

조회 수: 9 (최근 30일)
nanouk verhulst
nanouk verhulst 2017년 10월 11일
편집: Mischa Kim 2017년 10월 11일
Hi, I had to change values (below 60) in column 11 to the mean of a colomn 11. This worked (with the function below), but now I need to change values below 60 in colomn 11 to the previous value in column 11. I tried to figure it out by means of previous posts, but I can't make it work. Thanks!
>> lId = data(:,11) <= 60 ; data( data(:,11)<=60, 11 ) = mean(data(:,11));

답변 (1개)

Mischa Kim
Mischa Kim 2017년 10월 11일
Not quite sure if I understand what you are trying to do, but how about
data = 10*rand(5)
old = data(data(:,1)<=6,1)
data(data(:,1)<=6,1) = mean(data(:,1))
data(data(:,1)<=6,1) = old
I worked with a smaller size array and other numbers just to demonstrate.
  댓글 수: 3
Mischa Kim
Mischa Kim 2017년 10월 11일
What do you mean by previous? Same column, row above? Let's say you have a matrix
A = [1 2 3 4;...
5 6 7 8;...
9 10 11 12]
and had to replace all values below 10 in column 3.
nanouk verhulst
nanouk verhulst 2017년 10월 11일
편집: Mischa Kim 2017년 10월 11일
yes row above in same column. In your example it would not be the right value since 3 cannot be changed by the previous value (which should be higher than 10). so if the matrix would be
A = [9 10 11 12;...
8 7 6 5;...
4 3 2 1]
6 would have to become 11 and 2 would have to become 11

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by