vendredi 28 décembre 2018

how to subtract a value in a matrix which match a matrix condition?

% How to obtain matrix Md from matrix M matching next conditions:

% if M is:

M=[0.000000 1188.000000 340.216815
0.000000    1186.437500 570.718050
0.000000    1183.312500 769.256473
6.500000    1188.500000 331.115127
6.500000    1186.963013 510.419428
6.500000    1183.889160 719.346166
13.000000   1189.000000 325.858265
13.000000   1187.488647 426.599681
13.000000   1184.465942 671.896040
19.500000   1189.000000 330.567837
19.500000   1187.529785 383.856624
19.500000   1184.589478 643.279493
26.000000   1190.000000 333.606362
26.000000   1188.539795 381.784469
26.000000   1185.619263 648.680568];

% Find the maximum value of M(:,2) when M(:,1) is equal to (0, 6.5.. 26) this is:

for i=0:6.5:26
ind = M(:,1) == i;
max(M(ind,2))
end

% obtaining

ans = 1188
ans = 1188.5
ans = 1189
ans = 1189
ans = 1190

% The idea is to use these maximun values in order to substract them to the other values in M(:,2) when M(:,1) is equal to (0, 6.5.. 26). For example: the max value in M(:,2) when M(:,1)=0 is 1188, then we would substract to 1188: 1188, 1186.437500 and 1183.312500 which are the values of the M(:,2) column matching M(:,1)=0.

1188-1188 = 0.0000
1188-1186.437500 = 1.5625
1188-1183.312500 = 4.6875

% Then make the same sense with 6.5, 13..26. The Result would be:

Md=[0.000000    0.0000  340.216815
0.000000    1.5625  570.718050
0.000000    4.6875  769.256473
6.500000    0.0000  331.115127
6.500000    1.5370  510.419428
6.500000    4.6108  719.346166
13.000000   0.0000  325.858265
13.000000   1.5114  426.599681
13.000000   4.5341  671.896040
19.500000   0.0000  330.567837
19.500000   1.4702  383.856624
19.500000   4.4105  643.279493
26.000000   0.0000  333.606362
26.000000   1.4602  381.784469
26.000000   4.3807  648.680568];

Aucun commentaire:

Enregistrer un commentaire