How to input a set of data?? (not by [1 2 3 4 5])
Show older comments
Say the user has a set of data already as a vector call X, and I wish to let the user to input the variable X. Below is my code and the error I got:
D = input('Enter the data set:');
Enter the data set: X
??? Error using ==> input Undefined function or variable 'X'.
What should my code be if I want to let the user to enter just the variable instead of something like [1 2 3 4 5]??? HELP PLEASE!!!
Accepted Answer
More Answers (1)
Walter Roberson
on 1 Mar 2013
1 vote
Entering a variable name the way you do is fine, but the variable needs to exist in the same scope as the input() statement. If the user defined the variable (such as at the command line) and the input() is within a function then likely the scopes are not the same.
To accommodate this case you could read as a string and evalin('base', D). After, of course, validating that the input is a valid variable name and not (for example) a 'clear all' command.
Categories
Find more on Operating on Diagonal Matrices 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!