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

1 次查看(过去 30 天)
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'.

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by