Error using inputdlg() second time through same code
Show older comments
My code works fine on the first pass but when I press the button a second time I get an error.
answer is a local variable so is undefined until it's used both times
str = "Default Name";
answer = inputdlg("Enter a Name","New Name", ...
[1 30],str);
Error using inputdlg
Default Answer must be a cell array of character vectors.
Break point at answer = to check
K>> answer
Unrecognized function or variable 'answer'.
What's the deal? Both times through answer doesn't exist until it's created/assigned a value by inputdlg
3 Comments
Gavin
on 19 Sep 2024
Gavin
on 19 Sep 2024
"SO answer is ' ' type but my Options list have to be " "?"
No, it does not "have to be". The UICONFIRM documentation
states that the OPTIONS values may be either a cell array of character vectors or a string array. However, instead of providing the function with its documented input classes, you provided it with a single character vector:
['YES','NO'] % what you did: concatenate two character vectors into one character vector
Note that square brackets are a concatenation operator, not a "list" operator (which MATLAB does not have).
Although in this case UICONFIRM was gracious enough to accept your undocumented input, it is clear that what you provided it with was one option, not two (thus the error when you told it to use the nonexistent 2nd option).
In general, the best way to use functions is to follow their documentation:
{'YES','NO'} % cell array of character vectors
["Yes","No"] % string array
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!