Find and assign values in matrix

for n = 1:40 % loop over nodes with load
triNodes = qTop(n,:); % nodes of the considered triangle
triDof = globDof(triNodes,:)'; % degrees of freedom in global system
triCoord = nodeCoord(triNodes,1:nDim) % coordinates of triangle nodes
triCross(n,:) = cross((triCoord(1,:))-(triCoord(2,:)),(triCoord(1,:))-(triCoord(3,:)));
triAre(n,:) = (norm(triCross(n,:))/2) ;
q3(n,:)=[qTop(n,1) qTop(n,2) qTop(n,3) triAre(n,:)]
end
I have this code which produces the following output:
q3 =
1.0000 2.0000 90.0000 4.9424
2.0000 3.0000 91.0000 4.3018
3.0000 4.0000 92.0000 3.7912
4.0000 5.0000 93.0000 3.4618
5.0000 6.0000 94.0000 3.3465
6.0000 7.0000 95.0000 3.4566
7.0000 8.0000 96.0000 3.7815
8.0000 9.0000 97.0000 4.2892
9.0000 10.0000 98.0000 4.9293
10.0000 11.0000 99.0000 5.6382
...
Now i would lige to assign 1/3 of the value in the 4th column to each of the nodenumbers in the 1st, 2nd and 3rd column.
Thereafter i would like the sum of all values assigned to eachnode to be displayed besides the node in a 10x2 matrix.
Hope you can help, thanks in advance :)

4 件のコメント

dpb
dpb 2020 年 12 月 3 日
Not sure follow, but try
q3(:,1:3)=q3(:,1:3)+repmat(q3(:,4)/3,1,3);
or some variation on a theme depending upon what it is you really intend.
Simon Kibsgaard
Simon Kibsgaard 2020 年 12 月 3 日
編集済み: Simon Kibsgaard 2020 年 12 月 3 日
Sorry, I can get that to work as intended.
The numbers is column 1, 2 and 3 are the numbers of my nodes. Each row is the nodes of a triangle and the area of that triangle.
Now need the area of each triangle to be divided out onto each node of that triangle. At last i need all of the areas that are divided onto node number 1 to be sumed up and so forth for each node.
dpb
dpb 2020 年 12 月 3 日
Illustrate, don't just talk... :)
Give us the expected output from the above input.
Simon Kibsgaard
Simon Kibsgaard 2020 年 12 月 3 日
編集済み: Simon Kibsgaard 2020 年 12 月 3 日
Of course
I'd like the output to be like this:
1.0000 (4.9424/3)
2.0000 (4.9424/3)+(4.3018/3)
3.0000 (4.3018/3)+(3.7912/3)
4.0000 (3.7912/3)+(3.4618/3)
5.0000 (3.4618/3)+(3.3465/3)
6.0000 (3.3465/3)+(3.4566/3)
...
98.0000 (4.9293/3)
99.0000 (5.6382/3)
My dataset is much bigger than these 10 lines, otherwise it could have been done by hand.
Thanks for the help, it is very appereciated

サインインしてコメントする。

回答 (1 件)

Anmol Dhiman
Anmol Dhiman 2020 年 12 月 9 日

0 投票

Hi Simon,
Assuming your result stored in output (variable). follow the below code
areaIndex = output(:,4)/3;
finalOutput = zeros(100,2) % assuming number of nodes is 100
for i = 1:100
idx1 = find(output(:,1)==i);
idx2 = find(output(:,2)==i);
idx3 = find(output(:,3)==i);
sumArea = areaIndex(idx1) + areaIndex(idx2) + areaIndex(idx3);
finalOutput = [i sumArea];
end
Hope it helps,
Anmol Dhiman

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2020 年 12 月 3 日

回答済み:

2020 年 12 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by