Use Of ‘disp()’ Command In MatLab Programming

1 min reading time..

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.

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.

COMMENTS
There are no comments for this article yet! You can make the first comment.
Leave a Comment

x