Replacing values in array with values from another array
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
L'O.G.
el 17 de Jul. de 2022
Comentada: Star Strider
el 17 de Jul. de 2022
The values in each row of an array correspond to the values i, j of an upper triangular array. How do I return a vector with elements that are the corresponding i, j value in the array? For example:
test_array = [1 2; 2 3; 1 3];
test_upper_triangular_array = [0.5 0.25 0.7; 0 0.8 0.6; 0 0 1.1];
desired_vector = [0.25 0.6 0.7]
0 comentarios
Respuesta aceptada
Star Strider
el 17 de Jul. de 2022
Editada: Star Strider
el 17 de Jul. de 2022
Try this —
test_array = [1 2; 2 3; 1 3];
test_upper_triangular_array = [0.5 0.25 0.7; 0 0.8 0.6; 0 0 1.1]
lidx = sub2ind(size(test_upper_triangular_array), test_array(:,1), test_array(:,2)) % Convert Subscripts To Linear Indices
result = test_upper_triangular_array(lidx)
% desired_vector = [0.25 0.6 0.7]
EDIT —
Transpose to get row vector:
result_row = result.'
.
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!