Display variable name as output

조회 수: 22 (최근 30일)
ATHIRA P M
ATHIRA P M 2019년 3월 30일
댓글: Walter Roberson 2020년 5월 15일
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

채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 30일
편집: Walter Roberson 2019년 3월 30일
[B, idx] = sort(A);
fprintf('W%d ', idx);
fprintf('\n');

추가 답변 (1개)

P Sakthivel
P Sakthivel 2020년 5월 15일
convert it to a table to do this in just one command/line:
T=table(B)
You should get a display of the var. names and values, since the semi-colon at the end has been left out.
you can also access the names of the variables in table T using the syntax T.Properties.VariableNames
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 5월 15일
B is a row vector. The table that would be created would have a single variable named B that had a single row that was a row vector.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by