How to insert different figures into a report by using a for loop

2 views (last 30 days)
Hello,
I hope this finds you well. I have trying to create variables dynamically using a for loop but it seen possible. So I decided to do is create an array of string and try to convert them to variable and use them to insert figure in my generated report but it is not work. The main idea of my code is to dynamically create variables and assign figure() to them in order to create a figure for my graph. I have been working on this since last week and I cant seem to figure it out. Please, I would appreciate any help. Thank you in advance.
This is the codes I have currently
for x = 1: numChannels
figArray = ["fig1","fig2","fig3","fig4","fig5","fig6","fig7","fig8","fig9","fig10","fig11","fig12",...
"fig13","fig14","fig15","fig16","fig17","fig18","fig18"];
axisArray = ["ax1","ax2","ax3","ax4","ax5","ax6","ax7","ax8","ax9","ax10","ax11","ax12","ax13","ax14",...
"ax15","ax16","ax17","ax18","ax19","ax20"];
figImgArray = ["figImg1","figImg2","figImg3","figImg4","figImg5","figImg6","figImg7","figImg8","figImg9",...
"figImg10","figImg11","figImg12","figImg13","figImg14","figImg15","figImg16","figImg17"];
imgStyle = {ScaleToFit(true)};
figArray(x) = matlab.lang.makeValidName(figArray(x));
figArray(x) = figure("Color", "w");
axisArray(x) = axes(figArray(x), "FontSize", 12);
loglog(axisArray(x), xValues, channel(x,:), '-.b*');
axisArray(x).Title.String = ("Impedances at Channnel " + x );
axisArray(x).XLabel.String = "Frequency (Hz)";
axisArray(x).YLabel.String = "Impedance (Ω)" ;
figArray(x) = Figure(axisArray(x));
figImgArray(x) = Image(getSnapshotImage(figArray(x), report));
figImgArray(x).Style = imgStyle;
delete(gcf);
tableA = Table({figImgArray(x)});
tableA.entry(1,1).Style = {Width('3.2in'), Height('3in')};
%table3.entry(1,2).Style = {Width('3.2in'), Height('3in')};
end
add(report, tableA)
This is the error I get when I run this program
Error using string
Conversion to string from matlab.ui.Figure is not possible.

Answers (0)

Community Treasure Hunt

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

Start Hunting!