I have a list of objects in matrix A and object list and their corresponding masses in matrix B.Howto generate a matrix containing masses of objects present in orderof matrxA

1 visualización (últimos 30 días)
A = ["C"; "A"; "E"; "F"; "I"]
A = 5×1 string array
"C" "A" "E" "F" "I"
B = ["A", 1;"B", 34;"C" 56;"D" 32;"E",11;"F",8;"G", 7;"H",9;"I" 77]
B = 9×2 string array
"A" "1" "B" "34" "C" "56" "D" "32" "E" "11" "F" "8" "G" "7" "H" "9" "I" "77"

Respuesta aceptada

Voss
Voss el 31 de En. de 2023
A = ["C"; "A"; "E"; "F"; "I"]
A = 5×1 string array
"C" "A" "E" "F" "I"
B = ["A", 1;"B", 34;"C" 56;"D" 32;"E",11;"F",8;"G", 7;"H",9;"I" 77]
B = 9×2 string array
"A" "1" "B" "34" "C" "56" "D" "32" "E" "11" "F" "8" "G" "7" "H" "9" "I" "77"
[ism,idx] = ismember(A,B(:,1));
assert(all(ism))
result = B(idx,:)
result = 5×2 string array
"C" "56" "A" "1" "E" "11" "F" "8" "I" "77"

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by