print something in matlab

To print something in Matlab, you can use the disp function. For example, to print the string "Hello, world!", you would type:

main.m
disp('Hello, world!');
23 chars
2 lines

This will display the text on the command window. If you want to print a variable, you can just include it in the disp call:

main.m
x = 42;
disp(x);
17 chars
3 lines

This will print the value of x (in this case, 42) to the console.

You can also use fprintf function to display formatted text:

main.m
x = 42;
y = 'hello';
fprintf('The value of x is %d and the value of y is %s\n',x,y);
85 chars
4 lines

This will print "The value of x is 42 and the value of y is hello" to the console.

related categories

gistlibby LogSnag