Calling function with set parameters

2 ビュー (過去 30 日間)
Jucimar Carpe
Jucimar Carpe 2019 年 4 月 1 日
コメント済み: Jucimar Carpe 2019 年 4 月 1 日
Hi, i'm working on GUI and everytihgn is working fine!
Inside of my script i have i have to enter with some parameters and press "calculate" this will show me the results of my calculation in some box. But first of all, the user must choose one option from a list box. This wil give diferents results in that box.
The problem is that i want to reduce my script, many times i have wrote the same arguments for diferents situations...How can i do? See that i'm using set function!
polar=get(handles.caixa_polar,'value');
if (polar==1);
set(handles.corrente_Ia0,'String',sprintf('%g %s %gº', abs(Ia0), '/', (180*angle(Ia0))/pi))
set(handles.corrente_Ia1,'String',sprintf('%g %s %gº', abs(Ia1), '/', (180*angle(Ia1))/pi))
set(handles.corrente_Ia2,'String',sprintf('%g %s %gº', abs(Ia2), '/', (180*angle(Ia2))/pi))
set(handles.corrente_IA,'String',sprintf('%g %s %gº', abs(IA), '/', (180*angle(IA))/pi))
set(handles.corrente_IB,'String',sprintf('%g %s %gº', abs(IB), '/', (180*angle(IB))/pi))
set(handles.corrente_IC,'String',sprintf('%g %s %gº', abs(IC), '/', (180*angle(IC))/pi))
set(handles.tensao_Va0_pu,'String',sprintf('%g %s %gº', abs(Va0), '/', (180*angle(Va0))/pi))
set(handles.tensao_Va1_pu,'String',sprintf('%g %s %gº', abs(Va1), '/', (180*angle(Va1))/pi))
set(handles.tensao_Va2_pu,'String',sprintf('%g %s %gº', abs(Va2), '/', (180*angle(Va2))/pi))
set(handles.tensao_VA,'String',sprintf('%g %s %gº', abs(VA_fase), '/', (180*angle(VA_fase))/pi))
set(handles.tensao_VB,'String',sprintf('%g %s %gº', abs(VB_fase),'/', (180*angle(VB_fase))/pi))
set(handles.tensao_VC,'String',sprintf('%g %s %gº', abs(VC_fase), '/', (180*angle(VC_fase))/pi))
set(handles.corrente_Icc,'String',sprintf('%g %s %gº', abs(Icc), '/', (180*angle(Icc))/pi))
set(handles.tensao_aterramento,'String',sprintf('%g %s %gº', abs(V_aterramento), '/', (180*angle(V_aterramento))/pi))
else
set(handles.corrente_Ia0,'String',sprintf('%g%+gi', real(Ia0), imag(Ia0)))
set(handles.corrente_Ia1,'String',sprintf('%g%+gi', real(Ia1), imag(Ia1)))
set(handles.corrente_Ia2,'String',sprintf('%g%+gi', real(Ia2), imag(Ia2)))
set(handles.corrente_IA,'String',sprintf('%g%+gi', real(IA), imag(IA)))
set(handles.corrente_IB,'String',sprintf('%g%+gi', real(IB), imag(IB)))
set(handles.corrente_IC,'String',sprintf('%g%+gi', real(IC), imag(IC)))
set(handles.tensao_Va0_pu,'String',sprintf('%g%+gi', real(Va0), imag(Va0)))
set(handles.tensao_Va1_pu,'String',sprintf('%g%+gi', real(Va1), imag(Va1)))
set(handles.tensao_Va2_pu,'String',sprintf('%g%+gi', real(Va2), imag(Va2)))
set(handles.tensao_VA,'String',sprintf('%g%+gi', real(VA_fase), imag(VA_fase)))
set(handles.tensao_VB,'String',sprintf('%g%+gi', real(VB_fase), imag(VB_fase)))
set(handles.tensao_VC,'String',sprintf('%g%+gi', real(VC_fase), imag(VC_fase)))
set(handles.tensao_aterramento,'String',sprintf('%g%+gi', real(V_aterramento), imag(V_aterramento)))
end
%

採用された回答

Kevin Phung
Kevin Phung 2019 年 4 月 1 日
You can put all those graphic objects into an array, same for the strings and other parameters. then use a forloop.
short example:
g = [handles.corrente_Ia0 handles.corrente_Ia1 handles.corrente_Ia2];
I = [Ia0 Ia1 Ia2];
for i = 1:numel(g)
set(g(i),'String',sprintf('%g%+gi', real(I(i)), imag(I(i))));
end
  3 件のコメント
Kevin Phung
Kevin Phung 2019 年 4 月 1 日
yep, for loops should do all the repetitive work for you.The tricky part is storing your data and indexing properly.
Jucimar Carpe
Jucimar Carpe 2019 年 4 月 1 日
Yeah that's great! it worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by