Reputation: 63506
I'm trying to find the type of a struct field.
I tried to call prod
on what I thought was an array, but I got this error:
??? Error using ==> prod
Dimension argument must be a positive integer scalar within indexing range.
So I printed the object in question and found this:
K>> F.val
ans =
0.110000000000000 0.890000000000000
ans =
0.590000000000000 0.410000000000000 0.220000000000000 0.780000000000000
ans =
0.390000000000000 0.610000000000000 0.060000000000000 0.940000000000000
Which is different than the output of an array, which is this:
K>> [0.11 0.89 0.59 0.41 0.22 0.78 0.39 0.61 0.06 0.94]
ans =
Columns 1 through 4
0.110000000000000 0.890000000000000 0.590000000000000 0.410000000000000
Columns 5 through 8
0.220000000000000 0.780000000000000 0.390000000000000 0.610000000000000
Columns 9 through 10
0.060000000000000 0.940000000000000
and when I call class
on the object, I get this error:
K>> class(F.val)
??? Error using ==> class
The CLASS function must be called from a class constructor.
How can I find the type of F.val
?
Upvotes: 2
Views: 2719
Reputation: 74930
F
is most likely an array of structures. Thus, calling class(F.val)
is like calling class(F(1).val, F(2).val, F(3).val)
, which is different than the one-input-element syntax.
Use class(F(1).val)
to obtain the class of val
of the first element of F
.
By the way, the error with prod
is very likely of similar origin. prod(F(1).val)
works fine, however, with two inputs, the second is assumed to be a dimension argument, and that needs to be an integer (which can be of class double
, though).
Upvotes: 5