フィルターのクリア

problem of getting data from Simulink to Workspace with Matlab Fcn block

2 ビュー (過去 30 日間)
Sonny
Sonny 2011 年 7 月 20 日
Hello,
I'm trying to convert the hexadecimal numbers to ascii strings and pass it from Simulink to Workspace. To do that I used a Matlab Fcn block : function y = fcn(u) %#eml eml.extrinsic('assignin'); eml.extrinsic('strcat'); eml.extrinsic('plot');
Temp5 = ConvertToAscii(u(1),u(2),u(3),u(4));
assignin('base','Str_Digits',Temp5);
y = u(1);
So, when I click on the button 'Start simulation' in Simulink, I can see the output value change every time steps. However, when I launch a m file, I can only see the output after that m file execution finished. How to resolve this problem?
Thank you,
  3 件のコメント
Kaustubha Govind
Kaustubha Govind 2011 年 7 月 20 日
Do you mean that at the end of simulation, only the last value of 'Temp5' is available, and you really want it to be an array of strings?
Sonny
Sonny 2011 年 7 月 21 日
Indeed, I would like to visualize the evolution of the variable during the simulation. But here it's not possible, I only get the result at the end of the execution of m.file. However, if I don't stop the simulation after that, I can see the value change. So only during the execution of the script that I can't get the values

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 21 日
Your MATLAB Fcn block is also executed at every simulation step. Your statement assignin('base','Str_Digits',Temp5); over-write the variable "Str_Digits" in base workspace. Are you saying that you only saw one value of "Str_Digits"? Try to add the following line after that statement. Maybe you will see the value got updated continuously in the command window.
evalin('base','Str_Digits')
  1 件のコメント
Sonny
Sonny 2011 年 7 月 21 日
Indeed when I put it in the Fcn block, I get the value updated continuously in the command window. Of course in the command windows it could be annoying when executing a script, but it's already better than having nothing at all. Thank you

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

その他の回答 (1 件)

Rick Rosson
Rick Rosson 2011 年 7 月 21 日
Simulink does not support character or string data types. I would recommend that you do these calculations in MATLAB instead. If the data is being generated by a Simulink model, then you can simply pass the data from Simulink to the MATLAB Workspace using the "To Workspace" block, and then process the data using the "StopFcn" Callback Function.
There is no real advantage in trying to do this task with the MATLAB Function Block, and as you have discovered, there are many disadvantages in this case.
HTH.
  1 件のコメント
Maddila
Maddila 2012 年 12 月 20 日
if u use "to workspace" block also,,u wont get continuos updated values back to the base workspace

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by