Find the coordinates of the nodes of an matrix inside another matrix

2 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2024 年 5 月 20 日
回答済み: Matt J 2024 年 5 月 21 日
I would like to find the coordinates of the nodes of an matrix 'nodes_portion' inside a larger matrix 'nodes_e'. (In this case all 'nodes_portion' is contained in 'nodes_e').
What I want to get are the rows where the nodes of 'nodes_portion' are inside 'nodes_e'.
I am using a for loop however it takes much longer than expected. Any way to optimize the search?
nodes_file = importdata("nodes.mat");
nodes_e = nodes_file.nodes_e;
nodes_portion = nodes_file.nodes_portion;
row_t = {};
for j = 1:5 %:height(nodes_portion)
row = {};
for k = 1:height(nodes_e)
[r,~] = find(nodes_e(k,1) == nodes_portion(j,1) & nodes_e(k,2) == nodes_portion(j,2) & nodes_e(k,3) == nodes_portion(j,3));
row = [row;{r}];
end
row_t = [row_t;{row}];
end
% ==========
rr = {};
for s = 1:height(row_t)
[r,c] = find(cellfun(@(x) isequal(x,1), row_t{s,1}(:,1)));
rr = [rr;{r}];
end

採用された回答

Matt J
Matt J 2024 年 5 月 21 日
Sounds like you could just use ismember(___,'rows')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by