Calling function with set parameters

2 visualizaciones (últimos 30 días)
Jucimar Carpe
Jucimar Carpe el 1 de Abr. de 2019
Comentada: Jucimar Carpe el 1 de Abr. de 2019
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
%

Respuesta aceptada

Kevin Phung
Kevin Phung el 1 de Abr. de 2019
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 comentarios
Kevin Phung
Kevin Phung el 1 de Abr. de 2019
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 el 1 de Abr. de 2019
Yeah that's great! it worked!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by