How to select one of the array and change the array data selected with another value ?

1 次查看(过去 30 天)
example :
datasample [83 84 82 81 82 86 81 85 87 *88*];
if datasample > 87
datasample = mean(datasample);
end
I want change the biggest value in datasample that is 88 with mean ( 83)
how to code like that ?

采纳的回答

David Fletcher
David Fletcher 2018-3-19
编辑:David Fletcher 2018-3-19
datasample=[83 84 82 81 82 86 81 85 87 88];
datasample(datasample==88) = mean(datasample);
or more generally
datasample(datasample==max(datasample)) = mean(datasample)

更多回答(2 个)

Birdman
Birdman 2018-3-19
编辑:Birdman 2018-3-19
[~,idx]=max(datasample);
datasample(idx)=mean(datasample)

Muhammad Hafiz
Muhammad Hafiz 2018-3-19
Thank you for answer my question, both of you answer the correctly :)

类别

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