How to read and store user input as an integer.

16 ビュー (過去 30 日間)
Joshua Kabuya
Joshua Kabuya 2022 年 3 月 22 日
編集済み: Jan 2022 年 3 月 22 日
I'm making a program that takes user input and deals with arrays and such.
I have to take the users input and store it as a variable.
for example,
prompt = 'How many elements do you want to review?: ';
txt = input(prompt,"s");
i want to store what the user has put in as a variable so i can use a function later on.

回答 (1 件)

Jan
Jan 2022 年 3 月 22 日
編集済み: Jan 2022 年 3 月 22 日
Either:
num = input(prompt);
num = round(num); % to be sure
or:
txt = input(prompt, 's');
num = sscanf(txt, '%i', 1);

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by