Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaire
Stephen23
Stephen23 le 19 Avr 2020
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)

Connectez-vous pour commenter.

Réponses (1)

David Hill
David Hill le 19 Avr 2020
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;

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by