Find and assign values in matrix
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
dpb
le 3 Déc 2020
Illustrate, don't just talk... :)
Give us the expected output from the above input.
Réponses (1)
Anmol Dhiman
le 9 Déc 2020
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
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!