multiply all numbers above a threshold in a matrix by n, but only on certain indices, and keep original matrix dimension

2 ビュー (過去 30 日間)
Hi,
I want to multiply all numbers above a threshold in a matrix by n, but only on certain indices, and keep the original matrix dimension
so consider I have a 201x201 matrix, but only want to do my multiplication where y=1:115, I can do something like
matrix = rand(201,201);
matrix(matrix(:, 115) > 0.5) = 0;
which works great; but I want to something like
matrix(matrix(:, 115) > 0.5) = matrix .* 100;
but i can't of course because because the left and right sides have a different number of elements
I know this is super simple but please help me because I have a mind block
I think I need to make a logical mask, or something - but I can't think :-(

採用された回答

Jan
Jan 2019 年 4 月 15 日
編集済み: Jan 2019 年 4 月 15 日
index = (matrix(:, 115) > 0.5); % logical mask
matrix(index, 115) = matrix(index, 115) * 100;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by