Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get result of DISP as return parameter into a variable?

Tags:

matlab

Both functions disp and display do not have return parameters and display variable content into command window.

I would like to get the result of function call (displayed string) into a variable instead of output into command window, something like this str = ToString( myStruct ); where input variable is a MATLAB struct!

I am aware that display result depends on available width of command window, it can be either wide or narrow.

In all modern programming languages it would be a obj.ToString() method.

like image 548
Mikhail Poda Avatar asked Oct 05 '10 10:10

Mikhail Poda


People also ask

How many output values does DISP return?

The disp() function displays exactly one value/variable to the screen. The disp() function always uses one or more lines of output -- i.e., it always generates a carriage return at the end of its output.

How do you display results in Matlab?

disp( X ) displays the value of variable X without printing the variable name. Another way to display a variable is to type its name, which displays a leading “ X = ” before the value. If a variable contains an empty array, disp returns without displaying anything.


1 Answers

toString = @(x) evalc('disp(x)')

Not pretty, but it should get the job done.

like image 178
Edric Avatar answered Nov 15 '22 14:11

Edric