Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Rearrange variable in same column and define new variable

1 vue (au cours des 30 derniers jours)
fyza affandi
fyza affandi le 22 Oct 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have a table of probabilities arranged in descending order.
Symbol---- Probability
S1 ---- 0.7188
S2 --- 0.0625
S3 --- 0.0625
S4 ---0.0469
S5---0.0313
S6---0.0156
S7---0.0156
S8---0.0156
S9--- 0.0156
S10--- 0.0156
Then, I need to add the two minimum probability and named as a1( for this case S9+S10 =a1=0.0312). The next table would be arranged in descending order.
Symbol---- Probability
S1 ---- 0.7188
S2 --- 0.0625
S3 --- 0.0625
S4 ---0.0469
S5---0.0313
a1 --- 0.0312
S6---0.0156
S7---0.0156
S8---0.0156
My question is, how can I arrange the second table with the corresponding symbols and delete the two smallest probabilities?
and lastly creating the next table until only two symbols are left. p/s the next sum of smallest probability is a2, a3 ... p/s mine is just for 2nd column
mat = [ 0.7188 0.0625 0.0625 0.0469 0.0313 0.0156 0.0156 0.0156 0.0156 0.0156 ];
%Assign symbol number to perspective probability
for i = 1: length(mat)
S(i) = mat (i);
i= i+1;
end
%Adding the minimum probability
a(1)= S(end)+S(length(mat)-1);
%Rearrange the probability
for i = 1:(length(mat)-2)
mat2(i) = mat(i)
% mat3 =sort([mat2(i) a(1)])
i=i+1;
end
mat3= sort([mat2 a(1)]);
mat4 = sort(mat3,'descend');
col2 = mat4';

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by