How can I obtain new coordinates of elements in strings array?

1 vue (au cours des 30 derniers jours)
Keanu Guardiola Flores
Keanu Guardiola Flores le 30 Jan 2018
Modifié(e) : Matt J le 30 Jan 2018
I have an input like: A = ["e2_u3", "e4_u1", "e3_u2", "e_3_u1", "e2_u2", "e1_u1"]
and I want to create: M(i,j) = ["e1_u1" "e1_u2" "e1_u3"... "e1_uj" ;...;"ei_u1"..."ei_uj"].
In the case that the element exists in A, I want it to appear in M, and then I want to be able to say what was it's position in A.
Example:
txt= ["e2_u3", "e4_u1", "e3_u2", "e_3_u1", "e2_u2", "e1_u1"];
e = 4; u = 4;
order = strings(e,u);
for i=1:e
for m=1:u
if ismember(sprintf('e%d_u%d',i,m),txt)
order(i,m) = sprintf('e%d_u%d', i,m);
else
order(i,m)= 'Nan';
end
end
end
Now, I don't know how to tell the coordinate change from 'txt' to 'order'.

Réponse acceptée

Matt J
Matt J le 30 Jan 2018
Modifié(e) : Matt J le 30 Jan 2018
Call ismember with two outputs
[tf,loc]=ismember(sprintf('e%d_u%d',i,m),txt(:))
The output "loc" gives the location within txt(:).

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings 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