replace values by the previous value
1 次查看(过去 30 天)
显示 更早的评论
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));
0 个评论
回答(1 个)
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!