How can I add a workspace variable that is generated in a loop?

2 次查看(过去 30 天)
Hi there, thank you in advance, I am generating a report where I use plots and variables generated during a loop. Here's what I am doing: I run my m-file, get variables in work space and figures in different windows. Then, I run a report generator function. My plots are in the right order but my variables from the workspace are just shown for the last iteration, even though I see them in the workspace. I want to have this sequence in my report: Plot, variables, plot, variables... for all the iterations. I attached a screenshot of my report generator function so that you can see the structure of it (I could not attach a .rpt file here).
Should I add my whole m-file inside a "Evaluate MATLAB expression" so that RPG captures all of this information in the report?
Any insight will be very appreciated. Thank you!

采纳的回答

Nitin Khola
Nitin Khola 2015-8-5
A possible approach to solve this issue is to generate report using components in the Report Generator app. For your case, the components of interest are: For Loop (Logical and Flow Control category), Figure Snapshot (Handle Graphics category), Evaluate MATLAB expression (MATLAB category) and perhaps most importantly, the Variable Table (MATLAB category).
The Variable Table component displays a table containing information about all the variables in the MATLAB workspace. You can choose the kind of information to be displayed for variables, e.g. Name, Value, Memory etc. Hence, if the variables in the workspace are being dynamically changed, the table displays the workspace as it looks like at each iteration. For example, the following report was generated after two iterations using the aforementioned components in the Report Generator app. You can see that the variable "A2" was added in the second iteration.
To use the Report Generator in your case, you would have to modify each of the above components as per your script ("m-file"). For example, instead of writing a ‘for’ loop, use the For Loop component and include the commands that you want to execute in each iteration, in the Evaluate MATLAB expression component. You can learn more about it in the following documentation: You can learn more about it in the following documentation: http://www.mathworks.com/help/rptgen/ug/adding-components-to-the-report-template.html
  1 个评论
Julio Martinez
Julio Martinez 2015-8-11
编辑:Julio Martinez 2015-8-11
Thanks Nitin,
I tried this but I am only needing 8 out of about 30 variables that are in the workspace. I could not find a workaround from adding just the variables that I need when I added the component in Report Generator. It only gives me the options to select the variable's value, memory, dimension and class. Albeit, your suggestion placed the variables in the right order -after each plot-. I will go over the answer from Stephen and let you know what I get. Thank you for taking the time! I learned something.

请先登录,再进行评论。

更多回答(1 个)

Stephen23
Stephen23 2015-8-5
编辑:Stephen23 2019-6-28
  1 个评论
Julio Martinez
Julio Martinez 2015-11-16
Hi Stephen, Thanks a lot for your answer and for all the resources that pertain to my question. I finally got back to this part of my project and I am checking the storage of my variables using one of the techniques that you shared with me. I will try to edit this comment when I finally get this fully resolved.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by