Running my script multiple times and storing variables in a matrix

조회 수: 1 (최근 30일)
Noush
Noush 2022년 1월 14일
댓글: Noush 2022년 1월 14일
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
Noush
Noush 2022년 1월 14일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Max Heimann
Max Heimann 2022년 1월 14일
편집: Max Heimann 2022년 1월 14일
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
Noush
Noush 2022년 1월 14일
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 2022년 1월 14일
And also, my plot overlaps. Is there a way to define that the plots for the weeks are supposed to come after one another?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by