R like str() function in matlab/GNU Octave

孤街浪徒 提交于 2019-11-28 04:57:10

问题


I'd like to be able to view the structure of objects in Matlab/GNU Octave the same way as I do in R (using the str() function). Is there a function that does this? An example task would be returning nr rows and cols in matrix, but also all the arguments for a given function.

I'm aware that I could use both size() and help() (but not for function files) separately to get this information.


回答1:


There are several useful functions for displaying some information about Matlab objects (I can't say anything about Octave compatibility), but I'm not sure they'll provide the same detail as R's str(). You can display all of the methods of a class with the methods function, e.g.:

methods('MException')

which returns

Methods for class MException:

 addCause       getReport      ne             throw          
 eq             isequal        rethrow        throwAsCaller  

 Static methods:

 last

The what function will return similar results. Or methods can be used on an object of a given class:

ME = MException('Test:test','Testing');
methods(ME)

Similarly, you can view the properties with properties and the events with events.



来源:https://stackoverflow.com/questions/19815578/r-like-str-function-in-matlab-gnu-octave

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!