MATLAB Answers

Antony Vu
0

Help, I don't understand why the output multiplies everything by 1.0e+03

Antony Vu
さんによって質問されました 2019 年 11 月 16 日 5:27
最新アクティビティ Walter Roberson
さんによって コメントされました 2019 年 11 月 16 日 20:05
Problem:
The first column of matrix steamTable indicates the temperature of water in Celsius. The remaining colums indicate the thermodynamic properties of water at the specified temperature. Assign selectedData with all rows of steamTable that correspond to temperatures greater than loTemp and less than hiTemp.
Ex: If loTemp is 54 and hiTemp is 64, then selectedData is [55, 0.1576, 9.568, 2450.1; 60, 0.1994, 7.671, 2456.6;].
%my code
function selectedData = GetSteamTableData( loTemp, hiTemp )
% SelectLogicalN: Return rows of the steam table data between input
% low and high temperatures..
% Inputs: loTemp, hiTemp - input low and high temperatures for
% indexing rows of steam table
%
% Outputs: selectedData - returned rows of steam table data
% between low and high temperatures
% steamTable: first column is temperature (Celsius)
steamTable = [ 50, 0.1235, 12.032, 2443.5;
55, 0.1576, 9.568, 2450.1;
60, 0.1994, 7.671, 2456.6;
65, 0.2503, 6.197, 2463.1; ];
% Assign tempData with first column of steamTable data
tempData = steamTable(:,1);
% Assign selectedTemps with logical column array of
% temperatures between loTemp and hiTeamp
selectedTemps = (tempData >= loTemp) & (tempData < hiTemp) ;
% Assign selectedData with specified rows of steamTable (Hint:
% use row-column indexing and the colon operator)
selectedData = steamTable(selectedTemps,:);
end
and for some reason it always outputs this. Where is the 1.0e+03 coming from?
ans =
1.0e+03 *
0.0550 0.0002 0.0096 2.4501
0.0600 0.0002 0.0077 2.4566

  0 件のコメント

サインイン to comment.

1 件の回答

James Tursa
回答者: James Tursa
2019 年 11 月 16 日 5:38
 採用された回答

That's just the default way that MATLAB displays the numbers, rather that tacking e+03 to each number individually. You could use the format statement to change this, or use the fprint function if you want a custom format.

  2 件のコメント

Antony Vu
2019 年 11 月 16 日 19:59
Sorry, I am relatively new to matlab. Could you show what I could code so it does not multiply by e+03? I am trying to get the values [55, 0.1576, 9.568, 2450.1; 60, 0.1994, 7.671, 2456.6;]
Walter Roberson
2019 年 11 月 16 日 20:05
format long g
will cause it to not do that kind of multiplication.

サインイン to comment.



Translated by