Я создал класс в MATLAB:класса не сохраняет изменения, когда вызывается метод
classdef Compiler
%UNTITLED2 Summary of this class goes here
% Detailed explanation goes here
properties(Access = public)
in='' %a line of string of MATLAB code
out={} %several lines of string(cell array) of Babbage Code
end
methods(Access = private)
%compile(compiler);
expression(compiler);
term(compiler);
end
methods(Access = public)
function compiler = Compiler(str)
compiler.in = str;
expression(compiler);
compiler.out
end
end
И у меня есть функция выражение как:
function expression(compiler)
%Compile(Parse and Generate Babbage code)one line of MATLAB code
term(compiler);
end
и функцию term
как:
function term(compiler)
% Read Number/Variable terms
num = regexp(compiler.in, '[0-9]+','match');
len = length(compiler.out);
compiler.out(len+1,:) = {['Number ' num{1} ' in V0 in Store']};
compiler.out(len+2,:) = {['Number ' num{2} ' in V1 in Store']};
end
Когда я попытался запустить Compiler('3+1')
, выход пуст. Я попытался отлаживать его шаг за шагом, и я обнаружил, что когда функция term
закончила и вернулась к функции выражения, compiler.out
сменил с массива ячеек 2 x 1
на пустой.
Я смущен об этом. Я реализовал другие классы, подобные этому, и все их свойства могут быть изменены частной функцией моего класса.