7

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.

Mikhail Poda
  • 5,742
  • 3
  • 39
  • 52

3 Answers3

13

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

Not pretty, but it should get the job done.

Edric
  • 23,676
  • 2
  • 38
  • 40
2

struct2str might be a solution for your problem.

zellus
  • 9,617
  • 5
  • 39
  • 56
0

Consider using sprintf. You can write your own function for your data type if needed.

Memming
  • 1,731
  • 13
  • 25
  • That's exactly what I did not want to do. This post reflects my approach http://www.codinghorror.com/blog/2009/07/nobody-hates-software-more-than-software-developers.html – Mikhail Poda Nov 14 '10 at 20:43