Is there a Matlab function to convert any data structure to a string?

前端 未结 4 1266
情话喂你
情话喂你 2020-12-10 16:26

I\'m looking for a function in Matlab to use for error messages, like so:

error([\'Invalid value for someVariable: \' wantedFunction(someVariable)]);
         


        
4条回答
  •  粉色の甜心
    2020-12-10 17:00

    Come to think of it, I remember doing something a long time ago quite similar to what angainor has done in his answer. I'll post it here for anyone interested in converting arbitrary things to string, and generally having more control over how that conversion is done.

    It supports empties, logicals, chars, function handles, numerics, cells, struct (arrays), and user-defined classes (sparse arrays in the next update).

    EDIT: I've taken this as a template for an update that I ended up placing on the file exchange. Feel free to experiment it and modify to suit your needs.

提交回复
热议问题