Live script: section break inside a loop

13 visualizaciones (últimos 30 días)
ALBERTO BONARDI
ALBERTO BONARDI el 6 de Mayo de 2024
Editada: Harsh el 7 de Mayo de 2024
Hi everyone, im' trying to automatize a data analysis but i need to visually select 2 parameter from a graph. I was using two sliders to identify the two parameters that i'm intrest on but i need the possibility to change this value and see how the graph is modifiyng. My idea was to have two sliders that are associated at two lines in the graph and, whenever i modify one of theem the cod needs to re-run the section break till i'm satisfied with the result. The issue that i have is that the for loop in the beginning of the code is not finding the associated end when i'm using section break. Does someone know how to solve this problem?
dinfo = dir; %directory informations
dinfo(strncmp({dinfo.name}, '.', 1)) = []; % skip files and dir starting with '.'
rampa = 20; %WATT/min
rampaRate_coeff = rampa/60;
BaselineRamp = 20; % WATT
PO_MOD = 80; %WATT
BaselineWatts = 20;
NameFolder = struct2table(dinfo); % converting struct to table
NameFolder.folder = string(NameFolder.folder); % converting variable to string
NameFolder.name = string(NameFolder.name); % converting variable to string
NameFolder.NAMEDIR = NameFolder.folder+ "\" +NameFolder.name ; % New variable with directory name
resultTable = table();
for i = 1:height(NameFolder.NAMEDIR) %for loop for enterining in alla the folders
%other part of code
if sum(NameFolderDirectory_i_.name == 'MOD_RAMP.xlsx' | NameFolderDirectory_i_.name == 'HVYSTEP.xlsx') == 2 % if loop for checking if the condition written is true. If is it true then apply preprocessing and calculations
%other part of code
this part is the one that gaves me problem because of the section break. I would like to adjust VO2_LT and VO2_RCP using a slider and then re run only this section and decide wheter to go forward but if i insert a section break in this part the if and for don't find the end statement.
%TRESHOLDS IDENTIFICATION VISUALLY AND SAVING VALUES
VO2_LT = 1500 %%SLIDER
VO2_RCP = 2600 %%SLIDER
subplot(3,2,1) %VO22VE
plot(RAMPINT.VO2,RAMPINT.VE,'ko')
hold on
plot([VO2_LT VO2_LT], [min(RAMPINT.VE) max(RAMPINT.VE)], 'b');
hold on
plot([VO2_RCP VO2_RCP], [min(RAMPINT.VE) max(RAMPINT.VE)], 'r');
hold off
subplot(3,2,3) %VO2PETCO2
plot(RAMPINT.VO2,RAMPINT.PetCO2,'ko')
hold on
plot([VO2_LT VO2_LT], [min(RAMPINT.PetCO2) max(RAMPINT.PetCO2)], 'b');
hold on
plot([VO2_RCP VO2_RCP], [min(RAMPINT.PetCO2) max(RAMPINT.PetCO2)], 'r');
hold off
subplot(3,2,5) %VO2VEVCO2
plot(RAMPINT.VO2,RAMPINT.VEVCO2,'ko')
hold on
plot([VO2_LT VO2_LT], [min(RAMPINT.VEVCO2) max(RAMPINT.VEVCO2)], 'b');
hold on
plot([VO2_RCP VO2_RCP], [min(RAMPINT.VEVCO2) max(RAMPINT.VEVCO2)], 'r');
hold off
subplot(3,2,2) %VO2VCO2
plot(RAMPINT.VO2,RAMPINT.VCO2,'ko')
hold on
plot([VO2_LT VO2_LT], [min(RAMPINT.VCO2) max(RAMPINT.VCO2)], 'b');
hold on
plot([VO2_RCP VO2_RCP], [min(RAMPINT.VCO2) max(RAMPINT.VCO2)], 'r');
hold off
subplot(3,2,4) %VO2PetO2
plot(RAMPINT.VO2,RAMPINT.PetO2,'ko')
hold on
plot([VO2_LT VO2_LT], [min(RAMPINT.PetO2) max(RAMPINT.PetO2)], 'b');
hold on
plot([VO2_RCP VO2_RCP], [min(RAMPINT.PetO2) max(RAMPINT.PetO2)], 'r');
hold off
subplot(3,2,6) %VO2VEVO2
plot(RAMPINT.VO2,RAMPINT.VEVO2,'ko')
hold on
plot([VO2_LT VO2_LT], [min(RAMPINT.VEVO2) max(RAMPINT.VEVO2)], 'b');
hold on
plot([VO2_RCP VO2_RCP], [min(RAMPINT.VEVO2) max(RAMPINT.VEVO2)], 'r');
hold off
Can someone help me?

Respuestas (1)

Harsh
Harsh el 7 de Mayo de 2024
Editada: Harsh el 7 de Mayo de 2024
Hi,
From what I can gather, you are facing an issue with running a "for" loop which is spread across multiple sections.
As the "for" loop being spread across multiple sections the "end" command is not being executed when you run the "for" loop's section in MATLAB live script.
To avoid this issue, I would recommend you to keep the "end" command in the same section as the "for" loop but if that is not possible in your case, you can try running the entire MATLAB live script file by clicking the "RUN" button in the "Live Editor" tab of MATLAB desktop.
I hope this helps, thanks!

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by