Find and assign values in matrix

3 visualizaciones (últimos 30 días)
Simon Kibsgaard
Simon Kibsgaard el 3 de Dic. de 2020
Respondida: Anmol Dhiman el 9 de Dic. de 2020
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 comentarios
dpb
dpb el 3 de Dic. de 2020
Illustrate, don't just talk... :)
Give us the expected output from the above input.
Simon Kibsgaard
Simon Kibsgaard el 3 de Dic. de 2020
Editada: Simon Kibsgaard el 3 de Dic. de 2020
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

Iniciar sesión para comentar.

Respuestas (1)

Anmol Dhiman
Anmol Dhiman el 9 de Dic. de 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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by