Have you a registration already ? Sign In
Use Of ‘fprintf()’ In MatLab Programming With Examples
disp() is a very useful Matlab command that you can show values of variables inside sentences at command window. The alternative of disp() comman is fprintf() command is an also another useful command that you can use in this manner in Matlab programming. In here, we show you how to use disp() command in Matlab, with some examples below.
Take a look at the very basic example below to understand the use of disp() command in Matlab.
>> weight = 200;
height = 6.1;
disp( ['My height is ', num2str(height), ' and my weight is ', num2str(weight), '.']);
My height is 6.1 and my weight is 200.
>>
As you see above, we created a very basic code in Matlab command window. We created two variables callled ‘weight’ and ‘height’. And we want to create a sentence at command window by using disp() command.
Inside disp() command, you just need to add required words of your sentences inside quotes. Between the words, you need to place your variables.
At above example, we placed our variables by using ‘num2str()’ command which converts the numerical variables into strings.
When you are placing your variables, inside disp() command, you do not need to use quotes like other sentence words. Put comma between variables and sentence words.
YOU CAN LEARN MatLab IN MECHANICAL BASE; Click And Start To Learn MatLab!
By doing this, you can obtain meaningful sentences to show the user of code in Matlab command window.
Idea: You can take the values of variables from user, and you can create disp() codes with this values. This is a very basic logic of all the calculators.
As you see, disp() command is a very important command if you are serving your Matlab codes to other users.
If you wish further examples about disp() command in Matlab, please inform us at comments below.
Download And Install MatLab 2019!
Do not forget to leave your comments and questions about the use of disp() command in Matlab below.
Your precious feedbacks are very important for us.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Write Comments