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

2 vues (au cours des 30 derniers jours)
Julio Martinez
Julio Martinez le 3 Août 2015
Modifié(e) : Stephen23 le 28 Juin 2019
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!

Réponse acceptée

Nitin Khola
Nitin Khola le 5 Août 2015
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 commentaire
Julio Martinez
Julio Martinez le 11 Août 2015
Modifié(e) : Julio Martinez le 11 Août 2015
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Stephen23
Stephen23 le 5 Août 2015
Modifié(e) : Stephen23 le 28 Juin 2019
  1 commentaire
Julio Martinez
Julio Martinez le 16 Nov 2015
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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by