Reputation:
How to output class property so that it can be accessed in MATLAB's terminal? In my case, ClassA
stores p
array and shows output like:
ClassA with properties:
p: [3x3 double]
But when I want to access the array, its always says undefined function or variable. Although its public
.
My Code:
classdef Input
properties
p
end
methods
function obj = Input()
[obj.p] = input('Enter array like [a b c; d e f;]');
end
end
end
Upvotes: 1
Views: 364
Reputation: 30589
You probably need to clear all instances of Input
classes and rehash
your path to update the definition of the class.
I get:
>> myIn = Input;
Enter array like [a b c; d e f;][1 2 3; 4 5 6]
>> myIn
myIn =
Input with properties:
p: [2x3 double]
>> myIn.p
ans =
1 2 3
4 5 6
Upvotes: 1
Reputation: 36720
When you are using input
, you have to enter valid matlab code. Your command asks for a input like [a b c; d e f;]
, but the variables a-f are unknown. If you are intending to create a char array, use ['abc';'def']
Upvotes: 0