finding and sorting values in array
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi Again
Now i have an other issue sorting. Hope you can help me again.
I have the data as shown below.
The values in the first column are my node numbers and the values in the third column are the forces in each node. The second column show the dimension of the force.
I need all of the forces to be summed up, but the dimensions cant be mixed. i have also attached a example of the output f that i wish for. My data set is much bigger and therefore ii cant be done by hand.
30 3 -1.61e+04
31 3 -1.83e+04
32 3 -2.09e+04
33 3 -7.53e+03
89 3 -1.5e+04
90 3 -4.14e+04
91 3 -3.62e+04
92 3 -3.18e+04
93 3 -2.88e+04
94 3 -2.73e+04
95 3 -2.76e+04
96 3 -2.96e+04
97 3 -3.32e+04
98 3 -3.79e+04
99 3 -2.82e+04
30 3 -1.05e+03
31 3 -1.2e+03
32 3 -1.37e+03
33 3 -493
89 3 -986
90 3 -2.71e+03
91 3 -2.37e+03
92 3 -2.08e+03
93 3 -1.88e+03
94 3 -1.79e+03
95 3 -1.81e+03
96 3 -1.94e+03
97 3 -2.17e+03
98 3 -2.48e+03
99 3 -1.85e+03
1 1 1.43e+03
2 1 1.91e+03
3 1 1.67e+03
4 1 1.49e+03
5 1 1.38e+03
6 1 1.36e+03
7 1 1.42e+03
8 1 1.57e+03
9 1 1.79e+03
10 1 2.05e+03
11 1 752
23 1 1.39e+03
24 1 1.88e+03
25 1 1.65e+03
26 1 1.47e+03
27 1 1.38e+03
28 1 1.37e+03
29 1 1.45e+03
30 1 1.61e+03
31 1 1.83e+03
32 1 2.09e+03
33 1 753
89 1 1.5e+03
90 1 4.14e+03
91 1 3.62e+03
92 1 3.18e+03
93 1 2.88e+03
94 1 2.73e+03
95 1 2.76e+03
96 1 2.96e+03
97 1 3.32e+03
98 1 3.79e+03
99 1 2.82e+03
f=
30 3 -1.61e+04+(-1.05e+03)
31 3 -1.83e+04+(-1.2e+03)
32 3 -2.09e+04+(-1.37e+03)
33 3 -7.53e+03+(-493)
89 3 -1.5e+04+(-986)
90 3 -4.14e+04+(-2.71e+03)
91 3 -3.62e+04+(-2.37e+03)
92 3 -3.18e+04+(-2.08e+03)
93 3 -2.88e+04+(1.88e+03)
94 3 -2.73e+04+(-1.79e+03)
95 3 -2.76e+04+(-1.81e+03)
96 3 -2.96e+04+(-1.94e+03)
97 3 -3.32e+04+(-2.17e+03)
98 3 -3.79e+04+(-2.48e+03)
99 3 -2.82e+04+(-1.85e+03)
1 1 1.43e+03
2 1 1.91e+03
3 1 1.67e+03
4 1 1.49e+03
5 1 1.38e+03
6 1 1.36e+03
7 1 1.42e+03
8 1 1.57e+03
9 1 1.79e+03
10 1 2.05e+03
11 1 752
23 1 1.39e+03
24 1 1.88e+03
25 1 1.65e+03
26 1 1.47e+03
27 1 1.38e+03
28 1 1.37e+03
29 1 1.45e+03
30 1 1.61e+03
31 1 1.83e+03
32 1 2.09e+03
33 1 753
89 1 1.5e+03
90 1 4.14e+03
91 1 3.62e+03
92 1 3.18e+03
93 1 2.88e+03
94 1 2.73e+03
95 1 2.76e+03
96 1 2.96e+03
97 1 3.32e+03
98 1 3.79e+03
99 1 2.82e+03
0 Kommentare
Antworten (1)
Ameer Hamza
am 11 Dez. 2020
Bearbeitet: Ameer Hamza
am 11 Dez. 2020
Is the order of output matrix important? Try this
M = [
30 3 -1.61e+04
31 3 -1.83e+04
32 3 -2.09e+04
33 3 -7.53e+03
89 3 -1.5e+04
90 3 -4.14e+04
91 3 -3.62e+04
92 3 -3.18e+04
93 3 -2.88e+04
94 3 -2.73e+04
95 3 -2.76e+04
96 3 -2.96e+04
97 3 -3.32e+04
98 3 -3.79e+04
99 3 -2.82e+04
30 3 -1.05e+03
31 3 -1.2e+03
32 3 -1.37e+03
33 3 -493
89 3 -986
90 3 -2.71e+03
91 3 -2.37e+03
92 3 -2.08e+03
93 3 -1.88e+03
94 3 -1.79e+03
95 3 -1.81e+03
96 3 -1.94e+03
97 3 -2.17e+03
98 3 -2.48e+03
99 3 -1.85e+03
1 1 1.43e+03
2 1 1.91e+03
3 1 1.67e+03
4 1 1.49e+03
5 1 1.38e+03
6 1 1.36e+03
7 1 1.42e+03
8 1 1.57e+03
9 1 1.79e+03
10 1 2.05e+03
11 1 752
23 1 1.39e+03
24 1 1.88e+03
25 1 1.65e+03
26 1 1.47e+03
27 1 1.38e+03
28 1 1.37e+03
29 1 1.45e+03
30 1 1.61e+03
31 1 1.83e+03
32 1 2.09e+03
33 1 753
89 1 1.5e+03
90 1 4.14e+03
91 1 3.62e+03
92 1 3.18e+03
93 1 2.88e+03
94 1 2.73e+03
95 1 2.76e+03
96 1 2.96e+03
97 1 3.32e+03
98 1 3.79e+03
99 1 2.82e+03];
[grps, vals1, vals2] = findgroups(M(:,1), M(:,2));
vals3 = splitapply(@sum, M(:,3), grps);
M_out = [vals1 vals2 vals3]
Result
>> M_out
M_out =
1 1 1430
2 1 1910
3 1 1670
4 1 1490
5 1 1380
6 1 1360
7 1 1420
8 1 1570
9 1 1790
10 1 2050
11 1 752
23 1 1390
24 1 1880
25 1 1650
26 1 1470
27 1 1380
28 1 1370
29 1 1450
30 1 1610
30 3 -17150
31 1 1830
31 3 -19500
32 1 2090
32 3 -22270
33 1 753
33 3 -8023
89 1 1500
89 3 -15986
90 1 4140
90 3 -44110
91 1 3620
91 3 -38570
92 1 3180
92 3 -33880
93 1 2880
93 3 -30680
94 1 2730
94 3 -29090
95 1 2760
95 3 -29410
96 1 2960
96 3 -31540
97 1 3320
97 3 -35370
98 1 3790
98 3 -40380
99 1 2820
99 3 -30050
2 Kommentare
Ameer Hamza
am 11 Dez. 2020
It seems to be giving same output as you mentioned in your question. For example, first line in your question is this
30 3 -1.61e+04+(-1.05e+03)
If you look at the 30 3 line in my answer, it is same
30 3 -17150
Similarly, you can check other rows in your answer and match them with corresponding rows in my answer to see they are both same. Only the order of rows is different.
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!