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
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
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;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!