When I run a very simple m (prob.m ) file as: x = 1; y = 2; z= x+y;
I get the right answer in the workspace, but the command window just says the name of the file. What am I doing wrong?

댓글 수: 1

Stephen23
Stephen23 2015년 8월 18일
편집: Stephen23 2015년 8월 18일
A semi-colon after a command stops the output/s from being printed. You could:
  • remove the semi-colons (not recommended)
  • use an explicit disp command, e.g. disp(x).
  • use debugging tools to track variables.
  • change the script to a function and return some outputs.

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

 채택된 답변

Stalin Samuel
Stalin Samuel 2015년 8월 18일

0 개 추천

remove ; from end of each commands

댓글 수: 1

John D'Errico
John D'Errico 2015년 8월 18일
Note that this is arguably a very bad answer. It teaches the user to remove semi-colons from their lines, thus dumping large amounts of crap to the screen. That same user will then need to RELEARN to put semi-colons on their lines.
Instead, a far better answer would have suggested returning some arguments from the function, teaching what a function is and how it works. An answer might have suggested using the display/diap tools to dump SOME information to the screen as they might desire.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

태그

질문:

2015년 8월 18일

편집:

2015년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by