2

Can you please tell me how I can get multiple inputs from user in matlab? I thought of getting an array directly, but that doesn't seem to be possible. I tried the following

     velocity = input('Enter the velocities you want the aircraft to have at every node with space in between(m/s)','s');

and later use delimiter to read the numbers between spaces. But even for that, am not sure how to use the inbuilt functions.

     [u,remain] = strtok(velocity);

If there's no way to get multiple inputs directly, how can I put the above in a loop, so that I can read all the numbers? My apologies if the qustion is very rudimentary and your help will be much appreciated.

2 Answers 2

3

Give array as input

>> velocity = input('Enter the velocities you want the aircraft to have at every node with space in between(m/s)','s');
Enter the velocities you want the aircraft to have at every node with space in between(m/s) [1 2 3]
>> velocity

velocity =

 [1 2 3]

And then can use velocity(1), velocity(2), ... etc.

Or Use regex if you plan to give as comma separated input

>> velocity = input('Enter the velocities you want the aircraft to have at every node with space in between(m/s)','s');
Enter the velocities you want the aircraft to have at every node with space in between(m/s)1,2,3
>> result=regexp(velocity,',','split')

result = 

    '1'    '2'    '3'

(similarly you can use space too for separating inputs)

Sign up to request clarification or add additional context in comments.

1 Comment

There's a small error, I feel. The first one, doesn't give array directly. You have to remove the 's' parameter in the end of the input argument.
1

This can be done by:

result = input('prompt');

Matlab will prompt for your 'prompt' and you can enter for example [1 2 3]. The result will be vector with the previous numbers in it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.