Running my script multiple times and storing variables in a matrix

7 visualizaciones (últimos 30 días)
Hi,
I have a script (attached file) that produces five variables from the data of a chosen week (the user can chose a week in a user interaction box, the chosen number of the week is used to extract the needed data from the corresponding column of the table PVUebersicht) and a chosen percentage of one particular parameter.
Now I'd like to run the script 52 times, so I'd like to get the 5 variables for every week of the year and store it in a matrix. For all of those weeks the percentage would stay the same.
How is this possible? I need to somehow have a for loop in an external script, but how can I specify that each week has to be chosen and the percentage without changing the original script?
Thank you for your help!
  1 comentario
Noush
Noush el 14 de En. de 2022
When I use this for loop in a seperate script and just remove the dialog boxes, it runs 52 times through all the weeks, but it only saves the variables for week 52.
for Zahl_Woche=1:52
Jahresuebersicht
Jahr = [Eigenverbrauchsanteil Autarkiegrad AutarkiegradMobil AutarkiegradGrundlast AutarkiegradEinspeisung];
end

Iniciar sesión para comentar.

Respuesta aceptada

Max Heimann
Max Heimann el 14 de En. de 2022
Editada: Max Heimann el 14 de En. de 2022
I am not sure i understand what you are trying to achieve. What percentage are we talking about? It sounds like you want to call the function 52 times and store all results. In that case you need to define a different place to store your returned data for each loop cycle.
There are several ways to achieve this. E.g. Matlab allows array sizes to dynamically change during runtime. What you could do is initalize "Jahr" as an empty array and then append the new values each cycle.
Jahr = [];
for Zahl_Woche=1:52
Jahresuebersicht
Jahr = [Jahr; Eigenverbrauchsanteil Autarkiegrad AutarkiegradMobil AutarkiegradGrundlast AutarkiegradEinspeisung];
end
  3 comentarios
Noush
Noush el 14 de En. de 2022
Is there a way to do the same thing but as a table? I tried this and it again only calculates the last week:
sz = [52 6]; %Dimensionen der Jahresübersichttabelle
varArten = {'double','double','double','double','double','double'};%Arten der Variablen
varNamen = {'KGesamt','Eigenverbrauchsanteil','Autarkiegrad','AutarkiegradMobil','AutarkiegradGrundlast','AutarkiegradEinspeisung'};%Überschriften der Spalten in der Tabelle:
Jahr = table('Size',sz,'VariableTypes',varArten,'VariableNames',varNamen);
for Zahl_Woche=1:52
Jahresuebersicht
Jahr = [KGesamt Eigenverbrauchsanteil Autarkiegrad AutarkiegradMobil AutarkiegradGrundlast AutarkiegradEinspeisung];
end
Noush
Noush el 14 de En. de 2022
And also, my plot overlaps. Is there a way to define that the plots for the weeks are supposed to come after one another?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by