Home » All Programs » Use Of ‘disp()’ Command In MatLab Programming

Use Of ‘disp()’ Command In MatLab Programming

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.

How To Use disp() Command In MatLab?

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.

Conclusion For disp() Command In MatLab

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.

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


Please

leave feedback ?

( For the post )

ASK THE MECHANICALLAND

COMMUNITY


We are always open to your feedback to improve ourselves and the quality of our content! If you have any suggestions, thoughts, or criticism, please let us know. We are trying to improve our blog with constructive feedback. We are aware of how valuable your feedback is for our future development, and we will carefully read all your comments. Thank you in advance!