2017-12-11 10 views
0

まだScilabのロジックを理解しようとしていますが、私は機械的要素のための小さな計算ツールを作成しました。私が持っている主な問題は、計算コードの正しい順序(または構文)を見つけることです...私は多くの "不明な変数"のエラーを取得し、私はなぜ理解できませんか? 関数の定義の順序を変更しようとしましたが、変数をグローバルとして宣言しましたが、何も助けにはならないようです。 計算のコードが長く複雑ではありませんが、guiはguibuilderを使用して構築されているため、uicontrolsの定義は必要以上に長くなるでしょう。 複数の "問題ゾーン"が含まれていても、この例で多くのことを学び、理解するので、誰かがこのコードを動作させるのに役立つでしょうか?私は、コードが動的に入力されたスライダーとポップアップメニューの位置に応じて、グラフやパラメータテーブルを更新することを期待Scilab - gui - 多くの不明な変数のエラーメッセージ

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でプログラミングに関する多くの私の質問の答えを得るので、誰かがこのコードを働かせるのを助けることができれば、非常に役に立ちます。

ありがとうございます!

+2

Scilabでスコープがどのように制限されているかわからないことが問題です。関数内で変数を作成し、その関数の外から変数を呼び出そうとします。それは許されない。 – luispauloml

+1

あなたのコードを理解しようとしましたが、複雑すぎます。あなたはguibuilderで非常に簡単な例を作ることができますか?たぶん1つのスライダー、あるいは1つの単一の式?それは "未定義変数"と同じ問題を持つものでなければなりません。それが私たちが[mcve]と呼ぶものです。 – luispauloml

答えて

0

まず、あなたのコードは、改行のために直接実行可能ではありません。ステートメントの各行の後に...を追加してください。これにより、読みやすさも向上します。 @luispaulomlで述べたように、別の関数の内部にある変数を使用しようとします。たとえば、は、tab_param_callback(handles)で生きているtable_paramにアクセスしようとします。 は、このを取り除くためには、関数の出力を定義する必要があります。

機能を[table_values、table_param] = tab_param_callback(ハンドル)

table_values =文字列([WD WpのTalwd Malwdのalphaalwd]) ;

table_param = [table_titles; [table_values]];

ENDFUNCTION

今、あなたは、変数を取得するには、この関数を呼び出すことができます。

文字列(tab_param_callback(ハンドル))

私はこのケースを修正し、ドットを追加しました説明したように。他の変数についても同様に行うことができます。さらに、関数定義をコードの先頭に移動しました。スクリプトが途中でクラッシュした場合、コンパイラは関数定義を読む機会がないためです。

this fileにコードを記載してください。

こちらがお役に立てば幸いです。がんばろう!

+0

Btw:複数行にわたるステートメントの構文は、MATLAB.httpsと同じです。//de.mathworks.com/help/matlab/matlab_prog/continue-long-statements-on-multiple-lines.html – peng

関連する問題