MATLAB: Display variable name as output

ranking

Dear sir,
I sorted the values from lowest to highest. Output is display as values. I want to display it as variables. program is attached below
w1=0.3;
w2=0.4;
w3=0.3;
W1=(w1.* 2334)+(w2.* 141.1457)-(w3.*d1);
W2=(w1.* 2136)+(w2.* 134.3012)-(w3.*d2);
W3=(w1.*3160 )+(w2.*146.8276 )-(w3.*d3);
W4=(w1.* 1953)+(w2.* 109.2043)-(w3.*d4);
W5=(w1.* 1143)+(w2.* 108.3273)-(w3.*d5);
W6=(w1.* 3695)+(w2.* 174.3099)-(w3.*d6);
W7=(w1.* 7128)+(w2.* 223.9518)-(w3.*d7);
W8=(w1.* 5526)+(w2.* 225.4856)-(w3.*d8);
W9=(w1.* 7889)+(w2.* 204.7100)-(w3.*d9);
W10=(w1.* 1382)+(w2.* 116.3934)-(w3.*d10);
W11=(w1.* 9092)+(w2.* 230.4341)-(w3.*d11);
%W12=(w1.* 2334)+(w2.* 141.1457)-(w3.*d12);
W13=(w1.* 4995)+(w2.* 175.5827)-(w3.*d13);
W14=(w1.* 3768)+(w2.* 128.8066)-(w3.*d14);
W15=(w1.* 2867)+(w2.* 155.8670)-(w3.*d15);
A=[W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W13 W14 W15];
B=sort(A);
display(B)
output is shown as
B =
1.0e+03 *
Columns 1 through 10
0.3167 0.3835 0.5630 0.6317 0.6931 0.8656 0.9387 1.1206 1.1235 1.5232
Columns 11 through 14
1.7049 2.1850 2.4115 2.7920

Best Answer

  • [B, idx] = sort(A);
    fprintf('W%d ', idx);
    fprintf('\n');