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

1 回表示 (過去 30 日間)
Keanu Guardiola Flores
Keanu Guardiola Flores 2018 年 1 月 30 日
編集済み: Matt J 2018 年 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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by