类中未定义的函数或变量。

时间:2022-04-11 20:26:12

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:

如何输出类属性以便在MATLAB的终端中访问?在我的例子中,ClassA存储p数组并显示如下输出:

 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

2 个解决方案

#1


1  

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

#2


0  

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']

当您使用输入时,必须输入有效的matlab代码。您的命令要求输入[a b c];但是变量a-f是未知的。如果您打算创建一个char数组,请使用['abc';'def']

#1


1  

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

#2


0  

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']

当您使用输入时,必须输入有效的matlab代码。您的命令要求输入[a b c];但是变量a-f是未知的。如果您打算创建一个char数组,请使用['abc';'def']