Scaling a certain element

Hello
How do I scale a certain element in a matrix
if I want to get a certain type of element, like just the 2's or 5's and multiply them
A = [ 1 2 2; 4 5 1]
A==5 or A==2 MULTIPLY by 3
etc
thanks

回答 (1 件)

madhan ravi
madhan ravi 2019 年 1 月 23 日

0 投票

n=5; % certain element
idx=ismember(A,n);
a=A(:);
a(idx)=a(idx)*3;
R=reshape(a,size(A))
%OR
n=5;
idx=find(ismember(A,n));
[I,J]=ind2sub(size(A),idx);
R=A;
R(I,J)=R(I,J)*3

この質問は閉じられています。

タグ

質問済み:

2019 年 1 月 23 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by