【问题标题】:Error while entering data in a class properties in matlab在matlab的类属性中输入数据时出错
【发布时间】:2013-11-07 18:25:21
【问题描述】:

我在matlab中做了以下课程。

classdef details
%   SCORES Summary of this class goes here
%   Class for stroring the individual scores array of each of the
%   comparison of the models and the test files including the number of
%   coefficients used and number of gaussian 

properties(SetAccess=public)
    name;
    rollno=0;
    batch=0;
    branch;
    image;
end

methods
end
end

我正在通过以下方式访问它

detail=details;
detail.name=get(handles.edit2,'string');
detail.rollno=str2num(get(handles.edit3,'string'));

在运行程序时出现以下错误:

???不存在用于类详细信息的公共字段 rollno。

不知道哪里出错??????

【问题讨论】:

    标签: matlab class properties public


    【解决方案1】:

    尝试更改此设置

    properties(public)
    

    到这里

    properties(SetAccess = public)
    

    查看Matlab documentation了解更多信息

    【讨论】:

    • 即使进行了指定的更改,问题仍然存在。
    • 在 matlab 命令提示符下键入 which details 时会看到什么?它是否显示您的classdef details 所在的文件名?
    • 显示如下:D:\Users\Nikhil\Documents\MATLAB\details.m % details constructor
    • 我在一个名为 details.m 的文件中创建了 dis 'classdef details',我正在从同一路径中的不同 m 文件访问它。
    • 当我复制您的代码并完全按照您的描述进行操作时,这对我来说很好。也许您应该使用以下详细信息更新您的问题:操作系统、Matlab 版本以及对detail.rollno 的调用的更多上下文,这会给您带来错误。例如,它是脚本的一部分、函数的一部分、子函数的一部分等吗?没有更多信息,我没有想法。
    【解决方案2】:

    我遇到了和你一样的问题,我想我已经找到了原因。如果您在 MATLAB 工作区中有一个由该类定义的变量,则您无法更改它。也就是说,您可能有一个测试变量,它是一个“详细信息”类,并且在您添加“rollno”属性之前已初始化。尝试删除任何测试变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多