Running my script multiple times and storing variables in a matrix

2 ビュー (過去 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 Center および File ExchangeWhos についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by