I cannot get the input function to work

11 ビュー (過去 30 日間)
Brett C
Brett C 2020 年 4 月 30 日
コメント済み: Brett C 2020 年 4 月 30 日
I looked up the documentation for the input function, and when I copy and pasted an example, I get an error.
prompt = 'Do you want more? Y/N [Y]: ';
str = input(prompt,'s');
if isempty(str)
str = 'Y';
end
This code is in a brand new file called test.m, so those are the only 5 lines of code.
The error message is:
Index exceeds the number of array elements (9).
Error in test (line 2)
str = input(prompt);
I am in the latest version of matlab R2020a

採用された回答

Steven Lord
Steven Lord 2020 年 4 月 30 日
You have a variable named input in the base workspace (assuming you're running this from the prompt in the MATLAB Command Window) and MATLAB is interpreting that line of code as an attempt to index into that variable instead an attempt to call the function.
Rename or remove that variable.
  1 件のコメント
Brett C
Brett C 2020 年 4 月 30 日
Thanks I realized it wasn't giving an error when I used clear all in the beginning and just changed the variable name from "input" to "fileInput"

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by