need help on a simple question.

조회 수: 2 (최근 30일)
newiuht
newiuht 2012년 2월 8일
편집: Matt J 2013년 10월 4일
I've only entered as for the input. however, in the output, it shows "The char is s" and "The char is as". Can I know how do i get rid of the "The char is s" statement? Thank you.
Script:
%Prompt the user to enter a character followed by number
char = input ('Enter the character:','s');
num = input('Enter the number:');
%Print all variables in sentence format
fprintf ('The char is %4s\n','s',char)
fprintf ('The num is %5.2f\n', num)
command window:
>> prac2
Enter the character:as
Enter the number:23
The char is s
The char is as
The num is 23.00
  댓글 수: 1
Jan
Jan 2012년 2월 8일
CHAR is an important Matlab command, so do not shadow it by using it as a name of a variable.

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

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2012년 2월 8일
Hi,
please replace
fprintf ('The char is %4s\n','s',char)
with
fprintf ('The char is %s\n',char);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by