필터 지우기
필터 지우기

Problem with output of fprintf command

조회 수: 2 (최근 30일)
Craig Johnson
Craig Johnson 2022년 7월 30일
댓글: Steven Lord 2022년 7월 31일
function input(x)
Fw=0;
Fg=-12.9;
Bw=100;
Bg=197;
F=Fw+x*(Fg-Fw);
B=Bw+x*(Bg-Bw);
XX=x*100;
Line1_1='For an aqueous mixture of ';
Line1_2='glycol';
Line2_1='the freezing point is ';
Line2_2='Celcius and';
Line3_1='the boiling point is ';
Line3_2='Celcius';
fprintf(Line1_1 ,XX,Line1_2)
fprintf(Line2_1 ,F,Line2_2)
fprintf(Line3_1 ,B,Line3_2)
end
output: For an aqueous mixture of the freezing point is the boiling point is >>
Why is my function not including XX,B, and F in the output even though they are included in the fprintf functions? Just trying to figure out what code I'm missing to get the output to work correctly
  댓글 수: 1
Steven Lord
Steven Lord 2022년 7월 31일
In addition to the feedback about format specifiers in your fprintf calls that others have given you, I want to recommend that you change the name of your function because input already has a meaning in MATLAB.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 7월 30일
Look at the examples for fprintf in the documentation. You need to include a format specification to include variable values.
x = 2.5;
input(x)
For an aqueous mixture of 250 glycol the freezing point is -32.25 Celcius and the boiling point is 342.5 Celcius
function input(x)
Fw=0;
Fg=-12.9;
Bw=100;
Bg=197;
F=Fw+x*(Fg-Fw);
B=Bw+x*(Bg-Bw);
XX=x*100;
Line1_1='For an aqueous mixture of %g ';
Line1_2='glycol ';
Line2_1='the freezing point is %g ';
Line2_2='Celcius and ';
Line3_1='the boiling point is %g ';
Line3_2='Celcius ';
fprintf([Line1_1, Line1_2], XX)
fprintf([Line2_1,Line2_2], F)
fprintf([Line3_1,Line3_2], B)
end
  댓글 수: 1
Craig Johnson
Craig Johnson 2022년 7월 30일
thanks i did'nt realize i had forgotten %g thanks so much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pole and Zero Locations에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by