フィルターのクリア

How can i read and change the elements of a matrix A with its corresponding new values of elements stored in vector B ?

1 回表示 (過去 30 日間)
A1=[1 2 3; 4 4 6; 7 8 9]
A=reshape(A1,[1,9]);
Now i want to replace
1 with11
2 with 22
3 with 33
4 with 44
6 with 66
7 with 77
8 with 88
9 with 99
and the new values are stored in a vector as
B=[ 11 22 33 44 66 77 88 99]
  1 件のコメント
Stephen23
Stephen23 2020 年 4 月 19 日
Why does 44 only occur once in B even though the value 4 occurs twice in A ?
Why is the order of B as if you reshaped the data rowwise? (note that the data in A is arranged columnwise)

サインインしてコメントする。

回答 (1 件)

David Hill
David Hill 2020 年 4 月 19 日
Hard to know exactly what you want.
a=[1,2,3,4,6,7,8,9];
B=[ 11 22 33 44 66 77 88 99];
for k=1:length(a)
A(A==a(k))=B(k);
end
Why not just:
A=A*11;

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by