How can I supply input value interactively in MATLAB?

5 ビュー (過去 30 日間)
CHEO LEE
CHEO LEE 2023 年 10 月 6 日
回答済み: Walter Roberson 2025 年 9 月 8 日
Like in FORTRAN 'write(6,*) a ?' and 'read(5,*) a'

回答 (2 件)

Srikanth_Y
Srikanth_Y 2025 年 9 月 8 日
Hi Cheo Lee,
In MATLAB, interactive input from the user can be handled with the input function, which works similarly to FORTRAN’s read and write statements.
For example:
a = input('Please enter the value for a: ');
disp(['The value entered is: ', num2str(a)]);
This code will display a prompt in the command window and wait for a value to be typed in. The entered value gets stored in the variable a.
To accept text input, just add a second argument 's':
name = input('What is the name? ', 's');
disp(['Hello, ', name, '!']);
The input function is used for interactive input.
The disp or fprintf functions can display output, similar to FORTRAN’s write.
For further information and examples, kindly refer to the following documentation link:
Hope this helps.

Walter Roberson
Walter Roberson 2025 年 9 月 8 日
... among others.

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by