【问题标题】:Undefined Variable in MatlabMatlab中未定义的变量
【发布时间】:2012-03-20 22:11:16
【问题描述】:

以下是我的 MATLAB 程序的基本框架。每个框都是一个类定义。

向下滚动查看错误。 注意: 1. 每个Class都有一个自定义构造函数


错误

Undefined function or variable 'Troom'.

Error in ==> wall>wall.wall at 31
        function o = wall(Tr)

Error in ==> mainfile at 5
        w1 = wall();

这是当我从另一个文件“mainfile”创建 Class wall 对象时发生的


问题

  1. 为什么会这样?
  2. 我是否在特定于 Matlab 的 OOP 概念上弄错了?
  3. 我该如何解决这个问题?

提前致谢!


PS:代码

function o = wall()
        Tr = o.Troom*2;
        o.N = round(1/o.dx) + 1;
        o.T = Tr * ones(o.N,1);
        o.Tinf = Tr;
        o.update_properties();
    end

代码 2

classdef wall
properties
    dx = 0.01;
    dt = 0.4;
    L = 0.16;
    N;
    tlimit = 1505.2;
    sbc = 5.670400e-8 % The Stefan-Boltzmann Constant

    a;
    hi; % Surface Conductivity of Inner Surface
    bi;
    ho; % Surface Conductivity of Outer Surface
    bo;
    lamb;

    Troom = 298; % Room Temperature (K)
    Tinf;
    T;

    room = compartment();
    conc = concrete();
    fire = fireProperties(Troom);

end

【问题讨论】:

  • 实际代码会有所帮助,根据您给我们的内容无法说明发生了什么。
  • 我已将构造函数代码放在出现问题的地方。 :) 希望能帮助到你。其他类的代码很长,在这里可能无关紧要。
  • 我自己对为什么会发生这种情况感到困惑。因为。对于其他变量,情况并非如此。
  • 查看班级的properties 块也可能会有所帮助。

标签: oop matlab


【解决方案1】:
room = compartment();
conc = concrete();
fire = fireProperties(Troom);

是的,你的问题就在那里。 Troom 不能在 properties 块的上下文中使用。要么将常量放入 Troom,要么将它们移动到它们所属的构造函数中。

【讨论】:

  • 完成!伟大的!非常感谢!还有一个问题:Mathworks 上的 OOP 文档似乎冗长而混乱。 matlab OOP 有比 mathworks 更好的处理方法吗?
  • 如果你打算为科学计算做 OOP,你至少应该考虑使用 Python+numpy+scipy。 Python 比 Matlab、IMO 更适合 OOP。
  • kk。会调查的。谢谢! :)
猜你喜欢
  • 1970-01-01
  • 2015-03-28
  • 2012-04-15
  • 2013-02-24
  • 2023-03-08
  • 2013-09-27
  • 2021-11-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多