while loop in file called by GUI pushbutton not working correctly

Hi,
I'm having trouble with a while loop used in a file which is run by a GUI.
The loop keeps going until a variable (v1) reaches a limiting value, while it calculates another variable (v2) for every step v1 takes. v2 is then used to calculate other variables (v3 etc.) which are then used in a simulink model to give the value for v1.
It runs fine in the file, and when I highlight and 'evaluate section' the reference to it in the GUI this also works.
However, when I run the GUI and attempt to run it through a pushbutton v1 keeps looping at the same value. v2,v3 etc. change as usual, but v1 stays constant.
I think this is probably a problem to do with the variables being saved to the workspace correctly. Otherwise I have no idea why running through the GUI means it doesn't just run the file as normal.
I'm extremely stuck and have been for some time, so any help would be brilliant

6 件のコメント

Jan
Jan 2013 年 7 月 10 日
Please post the code instead of narrating the intention of the code.
Henry
Henry 2013 年 7 月 10 日
編集済み: Henry 2013 年 7 月 10 日
Code written in the file:
while round(Limit_term) ~= Limit_term_value;
i_C_peak = Seek_term;
Initial_Parameters_2_1
sim('Fixed_Freq_1_2.mdl', SimTime);
t_igbt_pk = max(logsout.HP2_Thermal_Model.t_igbt.Data);
Limit_term = t_igbt_pk
Seek_term_scalar = (Limit_term_value - Coolant_Delta) /(t_igbt_pk - Coolant_Delta);
Seek_term = Seek_term * Seek_term_scalar;
end
Jan
Jan 2013 年 7 月 10 日
And now clarify the relation to:
v1 keeps looping at the same value. v2,v3 etc. change as usual, but v1 stays constant.
Henry
Henry 2013 年 7 月 10 日
i_C_peak is used in 'Initial_Parameters_2_1' to calculate variables which are then used in the simulink model, which in turn calculates t_igbt_pk.
t_igbt_pk is the value which stays the same, while i_C_peak and variables in 'Initial_Paramaters_2_1' change (as they should). t_igbt_pk should also be changing.
Run as per usual I get:
i_C_peak =
50
I_diode_pk =
21.4019
Limit_term =
54.7397
i_C_peak =
147.2376
I_diode_pk =
56.3688
Limit_term =
62.7271
i_C_peak =
381.5518
I_diode_pk =
127.2914
For example.
Whereas if I run from the GUI:
i_C_peak =
50
I_diode_pk =
21.4019
Limit_term =
82.6201
i_C_peak =
97.1796
I_diode_pk =
38.9378
Limit_term =
82.6201
i_C_peak =
189.4226
I_diode_pk =
70.2521
Limit_term =
82.6201
i_C_peak =
371.2818
I_diode_pk =
124.3968
Jan
Jan 2013 年 7 月 10 日
@Henry: Should I assume that "Initial_Parameters_2_1" is an M-script?
Do you see that there is no hibnt how your Simulink model gets its inputs and writes its outputs? Perhaps you inject the output to the base workspace. Without knowing this, it is impossible to guess, why the program does not work as you expect it to.
Such problems are y typical effect of the transport of variables by "poofing", this means using scripts instead of functions, evalin, assignin etc.
Henry
Henry 2013 年 7 月 10 日
編集済み: Henry 2013 年 7 月 10 日
Yes, sorry
Initial_Parameters is an m script which calculates a load of variables which are then used in the simulink model.
the other terms in the while loop are declared in the .m file called by the GUI.
This line:
t_igbt_pk = max(logsout.HP2_Thermal_Model.t_igbt.Data);
Takes the data from a subsystem 'HP2_Th..' in the model if that helps?
I think you're right in that the simulink model isnt taking updated values to calculate t_igbt_pk (as this is the only variable calculated by the simulink model).

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

 採用された回答

Henry
Henry 2013 年 7 月 10 日

0 投票

I have figured out how to solve this!
I needed to add this to the while loop:
options=simset('SrcWorkspace','current','DstWorkspace','current');
sim('Fixed_Freq_1_2.mdl', SimTime,options);
So that the correct workspaces were being used.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Environment Customization についてさらに検索

製品

質問済み:

2013 年 7 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by