MATLAB: How to obtain new coordinates of elements in strings array

string arrays

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'.

Best Answer

Call ismember with two outputs
[tf,loc]=ismember(sprintf('e%d_u%d',i,m),txt(:))
The output "loc" gives the location within txt(:).