Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Help with compiling Matrix & Loop Function Please

3 ビュー (過去 30 日間)
Peter cullen
Peter cullen 2014 年 1 月 25 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have split the below nodes into a number of sub elements
node1 (0 0) node2 (0 6) node3 (6 6) node4 (6 0)
element1 nodes (1 2) element2 nodes (2 3) element3 nodes (3 4) element4 nodes (2 4)
>> sub_ele_nodes
sub_ele_nodes(:,:,1) =
0 0
0 1.5000
0 3.0000
0 4.5000
0 6.0000
sub_ele_nodes(:,:,2) =
0 6.0000
1.5000 6.0000
3.0000 6.0000
4.5000 6.0000
6.0000 6.0000
sub_ele_nodes(:,:,3) =
6.0000 6.0000
6.0000 4.5000
6.0000 3.0000
6.0000 1.5000
6.0000 0
sub_ele_nodes(:,:,4) =
0 6.0000
1.5000 4.5000
3.0000 3.0000
4.5000 1.5000
6.0000 0
I now wish to compile the above in one matrix, but I may have more elements than 4 so therefore I guess I need a loop. I also do not want any of the nodes repeating each other. Result should be:
>> nodes
0 0
0 1.5000
0 3.0000
0 4.5000
0 6.0000
1.5000 6.0000
3.0000 6.0000
4.5000 6.0000
6.0000 6.0000
6.0000 4.5000
6.0000 3.0000
6.0000 1.5000
6.0000 0
1.5000 4.5000
3.0000 3.0000
4.5000 1.5000
Please can someone help?

回答 (2 件)

Amit
Amit 2014 年 1 月 25 日
編集済み: Amit 2014 年 1 月 25 日
nodes = permute(sub_ele_nodes,[1 3 2]);
nodes = reshape(nodes,[],size(sub_ele_nodes,2),1);
nodes = unique(nodes,'rows','stable');
  2 件のコメント
Peter cullen
Peter cullen 2014 年 1 月 25 日
Hi Amit,
I put this into my code but all it is returning is 0 0. Im new to Matlab, and I recon I am doing something very simple wrong. Any Ideas? Thank you
Amit
Amit 2014 年 1 月 25 日
Before posting this, I tried it against the sub_ele_nodes that you provided in the question. And got exactly what you wanted.
I'd say before trying the code, try one time just typing
sub_ele_nodes
and checking if the matrix is still same.

Andrei Bobrov
Andrei Bobrov 2014 年 1 月 25 日
a = num2cell(sub_ele_nodes,[1 2]);
[aa,b] = unique(cat(1,a{:}),'first','rows');
[~,ii] = sort(b);
out=aa(ii,:);
  1 件のコメント
Peter cullen
Peter cullen 2014 年 1 月 25 日
Hi Andrei,
Thank you, I inputted this into my code & it returned 0 0. Im new to matlab so can you tell me if I am doing something incorrectly.
Peter

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by