0

I'm developing a MATLAB MEX-file (DLL) in C++ that I'm debugging with Visual Studio. I'm able to successfully step through the code but I'm having problems displaying the contents of certain variables (matrices).

Matrices are stored in contiguous blocks of memory float[N] or double[N] where N is a template parameter (N is known at compile time).

I need to control the precision of the formatting of the numbers in the matrices, and I'd also like the elements formatting a particular way (so they can easily be entered back in to MATLAB for comparison) so I wrote a quick printMat function to convert the matrix to a string. I then call this function in the immediate window when I want to inspect the contents of a matrix.

My problem: The immediate window only displays part of the string e.g.

"[ -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08...

This string should actually be.

"[ -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08]"

I can see the entire string if the matrix is smaller but that's just not an option in my case.

What I've tried so far :

  • Printing to std::cout
  • Printing to std::cerr

Unfortunately nothing displays on cout or cerr my guess is they are controlled by the MATLAB process and won't print anything until the debugger "releases" the process.

My question:

Is there a way to get an unadulterated version of this string from the immediate window? I really don't want to litter my code with print statements or temporary debugging string since that will require a rebuild each time I want to inspect the value of a new variable.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
kabla002
  • 321
  • 4
  • 13
  • If you're running in the debugger, just use the debugger to inspect the values in your array. – Cris Luengo Oct 03 '22 at 19:54
  • @Cris Luengo, I really need the matrix object formatted in the manner shown above (note the use of a semicolon to delimit every 3rd value) so I can use MATLAB to compare the values. Manually comparing larger sets of values is not tractable. It's also unclear what precision the debugger uses to print values. – kabla002 Oct 03 '22 at 20:03
  • Then print to stdout, and run without the debugger. Or better yet, early-terminate your MEX-file, returning these matrices as `mxArray`. Then you won't need to copy-paste and you'll have the exact values as they're in memory. – Cris Luengo Oct 03 '22 at 20:09
  • As I stated, I'd prefer not to have to litter the code with debug statements. The mex file is a wrapper around a library that has it's own matrix structure. These are intermediate values so it would be nice to be able to step through the code and not have to run to completion and then copy these values into mxArrays. Is getting visual studio to display arbitrary string impossible? – kabla002 Oct 03 '22 at 21:04
  • I don't know much about Visual Studio. I'm trying to understand your workflow. You're not using the debugger as a debugger. You want to pass intermediate results to MATLAB for analysis. I don't think that is something that should be done within a debugger. – Cris Luengo Oct 03 '22 at 21:11
  • What happens in you have your `printMat` function print the matrix on several lines? You can have a line break instead of a `;` in MATLAB code for a matrix literal. – Cris Luengo Oct 03 '22 at 21:16
  • My workflow is as follows. I have C++ and in MATLAB versions of an algorithm. Mex functions wrap the C++ version then I start a 2nd instance of MATLAB to run the MATLAB version. I then feed both versions the same values. When I notice a discrepancy, I step through the call to both implementations in parallel (2 separate processes). I then compare the outputs of the intermediate function calls to determine the source of the error. Unfortunately adding a line break does not resolve the issue, but thanks for the idea. – kabla002 Oct 04 '22 at 00:34

1 Answers1

0

You can reprot the problem to Developer Community and post link here. This is a compromise: there is a view button on the right. Click it and select text visualizer. Then you can see the string. enter image description here

enter image description here

Minxin Yu - MSFT
  • 2,234
  • 1
  • 3
  • 14