Scilab - gui - 许多未知变量错误消息

时间:2017-12-11 14:30:27

标签: scilab

仍然试图理解Scilab的逻辑,我为机械元素创建了一个小型计算工具。我遇到的主要问题是为计算代码找到正确的顺序(或语法)...我得到了很多"未知变量"错误,我不明白为什么? 我试图改变函数定义的顺序,将变量声明为全局等,但似乎没有任何帮助。 计算的代码不长也不复杂,但gui是使用guibuilder构建的,因此uicontrols定义可能比它们需要的时间长得多。 有人可以帮助我使这段代码正常工作,因为我会通过这个例子学习和理解很多,虽然它包含多个问题区域&#34 ;? 我在这里做了什么:

G = 78500;

table_titles = ["" "Wire diameter" "Wp" "Tau alwd" "M alwd" "Angle alwd"];

f=figure('figure_position',[910,163],'figure_size',
[903,537],'auto_resize','on','background',[33],'figure_name','Graphic 
window number %d');
//////////
delmenu(f.figure_id,gettext('File'))
delmenu(f.figure_id,gettext('?'))
delmenu(f.figure_id,gettext('Tools'))
toolbar(f.figure_id,'off')
handles.dummy = 0;
handles.sl_dwire=uicontrol(f,'unit','normalized','BackgroundColor',
[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma',
'FontSize',[12],'FontUnits','points','FontWeight','normal',
'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop',
[],'Max',[12],'Min',[0],'Position',
[0.0058208,0.77875,0.124375,0.06875],'Relief','default','SliderStep',
[0.1,1],'Style','slider','String',"Wire diameter",'Value',
[6],'VerticalAlignment','middle','Visible','on','Tag','sl_dwire',
'Callback','sl_dwire_callback(handles)')
handles.ed_dwire=uicontrol(f,'unit','normalized','BackgroundColor',
[-1,-1,-1],'Enable','off','FontAngle','normal','FontName','Tahoma',
'FontSize',[12],'FontUnits','points','FontWeight','normal',
'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop',
[],'Max',[1],'Min',[0],
'Position',[0.0058208,0.71875,0.124375,0.06875],'Relief',
'default','SliderStep',[0.01,0.1],'String',"wire diameter: " + 
msprintf('%2.1f',handles.sl_dwire.Value) + "mm",'Style','text',
'Value',[0],'VerticalAlignment','middle','Visible','on','Tag',
'ed_dwire','Callback','auto')
handles.sl_wangle=uicontrol(f,'unit','normalized','BackgroundColor',
[-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma',
'FontSize',[12],'FontUnits','points','FontWeight','normal',
'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left',
'ListboxTop',[],'Max',[180],'Min',[5],'Position',
[0.0090625,0.5191667,0.25625,0.0645833],'Relief','default',
'SliderStep',[0.1,1],'String','Working angle','Style','slider','Value',
[50],'VerticalAlignment','middle','Visible','on','Tag','sl_wangle',
'Callback','sl_wangle_callback(handles)')
handles.ed_wangle=uicontrol(f,'unit','normalized','BackgroundColor',
[-1,-1,-1],'Enable','off','FontAngle','normal','FontName','Tahoma',
'FontSize',[12],'FontUnits','points','FontWeight','normal',
'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left',
'ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.0090625,0.4591667,0.25625,0.0645833],'Relief','default',
'SliderStep',[0.01,0.1],'String',"Working angle: " + 
msprintf('%2.1f',handles.sl_wangle.Value) + "°",'Style','text',
'Value',[0],'VerticalAlignment','middle','Visible','on','Tag',
'ed_wangle','Callback','auto')
handles.sl_activel=uicontrol(f,'unit','normalized',
'BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal',
'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight',
'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left',
'ListboxTop',[],'Max',[1000],'Min',[10],'Position',
[0.0090625,0.365,0.25625,0.0645833],'Relief','default',
'SliderStep',[0.1,1],'String','Active length' ,'Style','slider',
'Value',[10],'VerticalAlignment','middle','Visible','on','Tag',
'sl_activel','Callback','sl_activel_callback(handles)')
handles.ed_activel=uicontrol(f,'unit','normalized',
'BackgroundColor',[-1,-1,-1],'Enable','off','FontAngle','normal',
'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight',
'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left',
'ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.0090625,0.305,0.25625,0.0645833],'Relief','default',
'SliderStep',[0.01,0.1],'String','Active length: ' + 
msprintf('%2.1f',handles.sl_activel.Value) +
"mm",'Style','text','Value',[0],'VerticalAlignment','middle','Visible',
'on','Tag','ed_activel','Callback','auto')
handles.ax_graph= newaxes();handles.ax_graph.margins = [ 0 0 0 0];
handles.ax_graph.axes_bounds = [0.4274266,0.0619266,0.3995485,0.5191743];
handles.tab_param=uicontrol(f,'unit','normalized','BackgroundColor',
[-1,-1,-1],'Enable','on','FontAngle','normal','FontName',
'Tahoma','FontSize',[12],'FontUnits','points','FontWeight','normal',
'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left',
'ListboxTop',[],'Max',[1],'Min',[0],
'Position',[0.4308126,0.1690826,0.3950339,0.2178899],'Relief',
'default','SliderStep',[0.01,0.1],'String',string(table_param),'Style',
'table','Value',[0],'VerticalAlignment','middle','Visible',
'on','Tag','tab_param','Callback','tab_param_callback(handles)')
handles.sl_sfactor=uicontrol(f,'unit','normalized',
'BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal',
'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight',
'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left',
'ListboxTop',[],'Max',[1],'Min',[0],
'Position',[0.0058208,0.6525688,0.124375,0.06875],'Relief','default',
'SliderStep',[0.01,0.1],'String',"Safety factor",'Style',
'slider','Value',[0.58],'VerticalAlignment','middle','Visible','on',
'Tag','ed_sfactor','Callback','sl_sfactor_callback(handles)')
handles.ed_sfactor=uicontrol(f,'unit','normalized',
'BackgroundColor',[-1,-1,-1],'Enable','off','FontAngle','normal',
'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight',
'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment',
'left','ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.0058208,0.5925688,0.124375,0.06875],'Relief','default',
'SliderStep',[0.01,0.1],'String',"Safety factor : " + 
msprintf('%2.1f',handles.sl_sfactor.Value),'Style',
'text','Value',[0.58],'VerticalAlignment','middle','Visible','on',
'Tag','ed_dwire','Callback','auto')
handles.popm_wtype=uicontrol(f,'unit','normalized',
'BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal',
'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight',
'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left',
'ListboxTop',[],'Max',[1],'Min',[0],'Position',
[0.0058208,0.8618349,0.124375,0.0639450],'Relief','default',
'SliderStep',[0.01,0.1],'String',gettext("SL/DL|SM/DM|SH/DH"),'Style',
'popupmenu','Value',[2],'VerticalAlignment','middle','Visible','on',
'Tag','popm_wtype','Callback','popm_wtype_callback(handles)')

//////////
// Callbacks are defined as below. Please do not delete the comments
as it will be used in coming version
//////////

function sl_sfactor_callback(handles)
   sf=handles.sl_sfactor.Value; 
   handles.ed_sfactor.String="Safety factor: " + msprintf('%3.2f',sf);
endfunction

function sl_dwire_callback(handles)
   wd=handles.sl_dwire.Value;
   Wp = %pi*wd^3/16;
   Ip =%pi*wd^4/32;
   Kt = G*%pi*Ip/(180*L);
   Talwd = sf * calcform;
   Malwd = Wp * Talwd;
   alphaalwd = Malwd / Kt;
   x=0:0.1:alphaalwd*1.5;
   plot(x,Kt*x);
   handles.ed_dwire.String="Wire diameter: " + 
   msprintf('%2.1f',wd) + "mm";
endfunction

function popm_wtype_callback(handles)
//Write your callback for  popm_wtype  here
     if selected == 1 then
     calcform =(1845 - 700*log10(wd));
 elseif selected == 2  then
     calcform =(2105 - 780*log10(wd));
 elseif selected == 3 then
     calcform = (2220 - 820*log10(wd));
 end
endfunction

function sl_wangle_callback(handles)
    handles.ed_wangle.String="Working angle: " + 
    msprintf('%2.1f',handles.sl_wangle.Value) + "°";   
endfunction

function sl_activel_callback(handles)
//Write your callback for  sl_activel  here
    handles.ed_activel.String="Active length: " + 
    msprintf('%2.1f',handles.sl_activel.Value) + "mm";
    L=handles.sl_activel.Value;
endfunction

function tab_param_callback(handles)
//Write your callback for  tab_param  here
   table_values = string([ wd Wp Talwd Malwd alphaalwd]);
   table_param = [table_titles; [table_values]];
endfunction

我希望代码根据输入滑块和弹出菜单的位置动态更新图形和参数表。

同样,如果有人可以帮助我使用此代码,那将会非常有帮助,因为我会得到很多关于scilab编程问题的答案。

非常感谢你!

1 个答案:

答案 0 :(得分:0)

首先,您的代码不能直接执行,这是由换行符引起的。请在语句的每一行后添加...。这也提高了可读性。 正如@luispauloml所提到的,您尝试使用存在于另一个函数内部的变量。例如,您尝试访问table_paramtab_param_callback(handles)中只有module Delayed module Backend module ActiveRecord class Job def retry! self.run_at = Time.now - 1.day self.locked_at = nil self.locked_by = nil self.attempts = 0 self.last_error = nil self.failed_at = nil self.save! end end end end end 。 要摆脱这种情况,您必须定义函数的输出:

  

function [table_values,table_param] = tab_param_callback(handles)

     

table_values = string([wd Talwd Malwd alphaalwd]);

     

table_param = [table_titles; [table_values]];

     

endfunction可写

现在你可以调用这个函数来获取变量:

  

的字符串(tab_param_callback(手柄))

我纠正了这个案例,并按照说明添加了点。对于其他变量,可以类似地完成。此外,我将函数定义移动到代码的开头。因为如果你的文章在中间崩溃,编译器就没有机会阅读函数定义。

请在this file中找到代码。

我希望这会有所帮助。祝你好运!