How can i select certain elements from a vector and set them to zero?
古いコメントを表示
I have the curve below. it is about a vector of 128 elements and i have to take just the peak and the rest must be replaced to zero. I think it is simple but i don't how because i am a beginner. I thought, i have to perhaps put the peak in anther vector and refill it with zeros but would it be take more time?

So I write the code below but i didn't get what i want, i am trying to creat a loop to test every element if it is smaller than zero and replace it to zero. The whole code workes without any changes in the curve and i get no error.
for i = 1 : length(Vector); % loop to test the elements of the curve from 1 to 128
VectorCurve = PPW ./ Rp + (C .* CPW); % the equation of the curve of 128 elements
if VectorCurve(i) < 0
VectorCurve (i) == 0;
end
end
Has anyone an idea to help me?
5 件のコメント
Paolo
2018 年 7 月 2 日
Do you just want the peak value or all positive values? You can remove replace negative values with zeros with logical indexing:
VectorCurve(VectorCurve<0) = 0;
Ruaa
2018 年 7 月 2 日
It is actually rare that you have to use a loop in matlab. Most likely, shifting the peak to 0 can be done in one line of code without a loop.
However, I have no idea what shifting the peak to 0 mean in practice. Please, give a numerical example of input and corresponging desired output.
Ruaa
2018 年 7 月 2 日
Ruaa
2018 年 7 月 2 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Axis Labels についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
