Have seen people ask about length of an input but never relative to Octave.
I would like to test the length of the user's response to an input command. I have already tried this method:
x=input('enter a set of numbers')
length(x)
This doesn't work. Entering "2345" will give you a length of 1, and entering "abcdefg" gives you an "undefined variable: abcdefg" error.
I have also tried:
x="blahblah"
length(x)
This gives the proper length, but I'm trying to test the length when x is equal to an input from a user, not predefined text.
For example, If the user inputs 5 numbers or 5 characters, I want the length to to be 5.
This length must also be usable in a vector. For example:
vector=[1,2,5,7,length(x),4]
How do I test the amount of CHARACTERS (letters or numbers) in the user's response?
In octav you should write the following:
x=input('enter a set of numbers', 's');
Add 's'
to specify that the input is string, or input the string by""
, for example "blahblah"
, without any change to your code. The other part of the code should work without any problem.