Help with operations between elements from a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, everybody
First of all, it is not a homework, it is a real operation that I need to do in my project, but I can't..
It is hard to explain, but I need to make a ponderation between elements with the same ID using the values from a column. The exactly operations are in the comments below:
26 1 % 26/26 = 1
35 2 % 35/35 = 1
27 3 % 27/27 = 1
25 4 % 25/25 = 1
41 5 % 41/(41+28+34) = 0.3981
28 5 % 28/(41+28+34) = 0.2718
34 5 % 35/(41+28+34) = 0.3398
34 6 % 34/(34+34) = 0.5
34 6 % 34/(34+34) = 0.5
29 7 % 29/(29+34) = 0.4603
34 7 % 34/(29+34) = 0.5397
24 8 % 28/28 = 1
35 9 % 35/(35+38+29+28) = 0.2692
38 9 % 38/(35+38+29+28) = 0.2923
29 9 % 29/(35+38+29+28) = 0.2231
28 9 % 28/(35+38+29+28) = 0.2154
40 10 % 40/(40+34) = 0.5405
34 10 % 34/(40+34) = 0.4594
The solution would be:
26 1 1
35 2 1
27 3 1
25 4 1
41 5 0.3981
28 5 0.2718
34 5 0.3398
34 6 0.5
34 6 0.5
29 7 0.4603
34 7 0.5397
24 8 1
35 9 0.2692
38 9 0.2923
29 9 0.2231
28 9 0.2154
40 10 0.5405
34 10 0.4594
I don't know if I made it really clear, but I really need help here.
Att,
Paulo
0 Kommentare
Akzeptierte Antwort
Voss
am 28 Jan. 2022
data = [ ...
26 1; ...
35 2; ...
27 3; ...
25 4; ...
41 5; ...
28 5; ...
34 5; ...
34 6; ...
34 6; ...
29 7; ...
34 7; ...
24 8; ...
35 9; ...
38 9; ...
29 9; ...
28 9; ...
40 10; ...
34 10; ...
];
data(:,end+1) = 0;
[uID,~,jj] = unique(data(:,2));
for ii = 1:numel(uID)
idx = jj == ii;
data(idx,end) = data(idx,1)./sum(data(idx,1));
end
disp(data);
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!