Reputation: 4791
Im Matlab the properties
function sounds like a possible valid equivalent to commands in R that acquaint you with a particular object in the working environment, providing information as to its structure (data.frame, matrix, list, vector) and type of variables (character, numeric) (for example, with the R command str()
), dimensions (using perhaps the call dim()
), and names of the variables (names()
).
However, this function is not operational in Octave:
>> properties(data)
warning: the 'properties' function is not yet implemented in Octave
I installed the package dataframe
as suggested in a comment on the post linked above:
pkg install -forge dataframe
and loaded it pkg load dataframe
But I can't find a way of getting a summary of the structure and dimensions of a datset data.mat
in the workspace.
I believe it's a structure consisting of a 4 x 372,550 numerical matrix; two 4 x 46,568 numerical matrices, and a 256 x 1 character matrix. To get this info I had to scroll through many pages of the printout of data.
This info is not available on the Octave IDE, where I get:
Name Class Dimensions
data struc 1 x 1
a far cry from the complexity of the object data
.
What is the smart way of getting some this information about an object in the workspace in Octave?
Following up on the first answer provided, here is what I get with whos
:
>> whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
data 1x1 7452040 struct
Total is 1 element using 7452040 bytes
This is not particularly informative about what data
really contains. In fact, I just found out a way to extract the names inside data
:
>> fieldnames(data)
ans =
{
[1,1] = testData
[2,1] = trainData
[3,1] = validData
[4,1] = vocab
}
Now if I call
>> size(data)
ans =
1 1
the output is not very useful. On the other hand, knowing the names of the matrices within data
I can do
>> size(data.trainData)
ans =
4 372550
which is indeed informative.
Upvotes: 0
Views: 2216
Reputation: 60444
If you type the name of the variable, you'll see information about it. In your case it's a struct, so it'll tell you the field names. Relevant functions are: size
, ndims
, class
, fieldnames
, etc.
size(var)
class(var)
etc.
You refer to .mat
. Maybe you have a MAT-file, which you can load with load filename
. Once loaded you can examine and use the variables in the file.
whos
prints simple information on the variables in memory, most useful to see what variables exist.
Following up on your edited question. This works in Octave:
for s=fieldnames(data)'
s=s{1};
tmp=data.(s);
disp([s,' - ',class(tmp),' - ',mat2str(size(tmp))])
end
It prints basic information of each of the members of the struct. It does assume that data
is a 1x1 struct array. Note that a struct can be an array:
data(2).testData = [];
Causes your data
struct to be a 2x1 array. This is why size(data)
is relevant. class
is also important (it's shown in the output of whos
. Variables can be of type double
(normal arrays), and other numeric types, logical
, struct
, cell
(an array of arrays), or a custom class that you can write yourself.
I highly recommend reading an introductory text on MATLAB/Octave, as it works very differently from R. It's not just a different flavor of language, it's a whole different world.
Upvotes: 2