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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by