Printing values to the command window

how does one print a value of a variable to the command window?

2 件のコメント

Matthew White
Matthew White 2017 年 1 月 21 日
type the variable in the script window without a semicolon then run the code
Image Analyst
Image Analyst 2017 年 1 月 21 日
You got it backwards. Typing the variable name first and then running the code will likely get you a "variable name not defined" error message. You have to do it like I said in my answer below. Run the code first, then execute the variable name without a semicolon.

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2012 年 1 月 12 日

2 投票

Or you can simply list the variable all by itself on a line of code:
m = 10.42;
fprintf('m = %f\n', m); % Method 1
disp(m); % Method 2
m % Method 3. Note: no semicolon, just the name.
str = sprintf('%f\n', m) % Yet another method - returns a string

1 件のコメント

Wesley
Wesley 2026 年 1 月 31 日 0:05
youre lovely

サインインしてコメントする。

Honglei Chen
Honglei Chen 2012 年 1 月 12 日

0 投票

Use fprintf
doc fprintf

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 1 月 12 日
or disp()
Isabella, a couple of technical notes:
- if you do not specify any file identifier for the fprintf() call, then the default is to go to the command window
- the file identifier 1 (the number) is defined as going to the command window.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

質問済み:

2012 年 1 月 12 日

コメント済み:

2026 年 1 月 31 日 0:05

Community Treasure Hunt

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

Start Hunting!

Translated by