嘿伙计们。好的。我已经完成了这个编码。但它似乎有错误。谁能向我解释为什么会出现错误?这是编码:
Hcurve = cell2mat(get(handles.Mytable3,'Data'));
costA = cell2mat(get(handles.Mytable1,'Data'));
cost1 = str2num(get(handles.input2_editText,'String'));
cost2 = str2num(get(handles.input3_editText,'String'));
cost3 = str2num(get(handles.input4_editText,'String'));
cost4 = str2num(get(handles.input5_editText,'String'));
limit = cell2mat(get(handles.Mytable2,'Data'));
Pdt = str2num(get(handles.input1_editText,'String'));
if isempty(costA)
if size(Hcurve,1) == 2
H1 = Hcurve(1,:)*cost1;
H2 = Hcurve(2,:)*cost2;
H = num2cell([H1;H2]);
set(handles.Mytable1,'Data',H)
cost = cell2mat(get(handles.Mytable1,'Data'));
else if size(Hcurve,1) == 3
H1 = Hcurve(1,:)*cost1;
H2 = Hcurve(2,:)*cost2;
H3 = Hcurve(3,:)*cost3;
H = num2cell([H1;H2;H3]);
set(handles.Mytable1,'Data',H)
cost = cell2mat(get(handles.Mytable1,'Data'));
else if size(Hcurve,1) == 4
H1 = Hcurve(1,:)*cost1;
H2 = Hcurve(2,:)*cost2;
H3 = Hcurve(3,:)*cost3;
H4 = Hcurve(3,:)*cost4;
H = num2cell([H1;H2;H3;H4]);
set(handles.Mytable1,'Data',H)
cost = cell2mat(get(handles.Mytable1,'Data'));
else
cost = costA;
end
end
end
end
if size(cost,1) == 1
set(handles.text8,'String','At Lease Two Generators');
这是发生的错误:
???在编译时,“cost”被确定为一个变量并且这个变量是未初始化的。“成本”也是一个函数名称,以前版本的 MATLAB 会调用该函数。但是,MATLAB 7 禁止在相同的上下文中使用相同的名称作为函数和变量。
==> fyp_editor>Mybutton_Callback 在 131 如果 size(cost,1) == 1 时出错
==> gui_mainfcn 中的错误 96 feval(varargin{:});
==> fyp_editor 中的错误 42 gui_mainfcn(gui_State, varargin{:});
==> @(hObject,eventdata)fyp_editor('Mybutton_Callback',hObject,eventdata,guidata(hObject)) 中的错误
???评估 uicontrol 回调时出错