Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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 Commento
Stephen23
Stephen23 il 19 Apr 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)

Accedi per commentare.

Risposte (1)

David Hill
David Hill il 19 Apr 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;

Categorie

Scopri di più su Read, Write, and Modify Image in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by