When you are creating your programs in Matlab, you can obtian the values of different variables from users to make calculations or further operations by using them. In here, we will show you how to take values from users for different variables in MatLab.
Table of Contents ;
How To Take Inputs From Users In MatLab?
>> a = input('Enter the required value for a:'); % b = input('Enter the required value for b:'); x= a*b %From now on, this is commend window. Enter the required value for a:5 %user enters the value of a Enter the required value for b:6 %user enters the value of b x = 30
As you see above example, you can take the user inputs by using the code called ‘input’. For example, you want that the value of ‘a’ and ‘b’ are defined by the user of code. So, you can equalize the variables to ‘input()’ and you can type the message for user inside the pharanteses like above example.
YOU CAN LEARN MatLab IN MECHANICAL BASE; Click And Start To Learn MatLab!
If you take the values of different variables like above in Matlab, you can use them;
- At further mathematical programs.
- You can use in functions that are created in Matlab.
- You can use these variables inside ‘for-end’ loops in Matlab.
- Also you can use these variable that are taken from users inside ‘if-else’ queries.
You can create various kinds of codes and programs for users by using Matlab programming language.
Taking Inputs As Strings From User In MatLab
Also, user can give answers in string format from their keyboards in Matlab. Take a look at the below example;
x = input('Are you an engineer(type Y or N)?','s'); if x == 'Y' disp('You can become a great engineer in Mechanicalland!'); elseif x == 'N' disp('You can learn lot sof engineering topics in Mechanicalland!'); end
The difference of taking string inputs from users in Matlab that you need to type ‘,’s” after the prompt inside the input. You can create queries like above by using if-else queries like above.
This can be a general expression of getting inputs from users in Matlab to variables. If you want further coding examples about this topic, please leave your comments about it below.
Do not forget to leave your comments and questions about ‘input’ command in Matlab below.
Your precious feedbacks are very important for us.
Leave a Reply