Increase nonzero values without deleting zeros
古いコメントを表示
I have a vector X.
X=[0 0 0 0 1 1 1 1 0 0 0 0 0 0 2 2 2 2 2 2 0 0 0 3 3 3 3 0 0 0 0 0 4 4 4]
I want to increase the values of the nonzero elements in vector X by 10 However, when I do this using the find function I end up just having a vector without the zeros.
Y=X((find(X~=0)))+10;
Y=[11 11 11 11 22 22 ... ]
Is there a way to do this without using a for loop?
2 件のコメント
KSSV
2017 年 4 月 12 日
Where you want to place the non zeros numbers?
採用された回答
その他の回答 (1 件)
Adam
2017 年 4 月 12 日
X = ( X ~= 0 ) .* ( X + 10 );
カテゴリ
ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!