Storing output into a matrix for plotting

1 回表示 (過去 30 日間)
Dylan Springer
Dylan Springer 2020 年 9 月 16 日
コメント済み: Dylan Springer 2020 年 9 月 16 日
Hello, My graph is showing up but its only plotting the last value. I understand that the vals variable is only storing the last output and that is why but how do I get it to store the value into a matrix after each run through the loop without overwriting. I need the output to be a graph of rho vs average revenue.
N = 5000;
Rmax = 50;
total_revenues = zeros(length(N),1);
charge_eff = 0.8;
discharge_eff = 0.8;
vals = [];
for rho = (0.1:0.1:3)
for n = 1:N
R = zeros(24,1);
x = zeros(24,1);
P_d = zeros(24,1); P_d(1) = 50;
P_s = zeros(25,1);
W = zeros(25,1);
revenues = zeros(24,1);
for t = 1:24
... (code to get answer)
end
total_revenues(n) = sum(revenues);
end
rho
avgrev = mean(total_revenues)
vals = [rho avgrev];
end
plot (vals)

採用された回答

KSSV
KSSV 2020 年 9 月 16 日
I expect rho is bein gused in the lines which are not shown...so repalce rho inside the loop with rho(i).
N = 5000;
Rmax = 50;
total_revenues = zeros(length(N),1);
charge_eff = 0.8;
discharge_eff = 0.8;
vals = zeros([],1);
rho = (0.1:0.1:3) ;
for i = 1:length(rho)
for n = 1:N
R = zeros(24,1);
x = zeros(24,1);
P_d = zeros(24,1); P_d(1) = 50;
P_s = zeros(25,1);
W = zeros(25,1);
revenues = zeros(24,1);
for t = 1:24
... (code to get answer)
end
total_revenues(n) = sum(revenues);
end
rho(i)
avgrev = mean(total_revenues)
vals(i) = avgrev;
end
plot (rho,vals)
  1 件のコメント
Dylan Springer
Dylan Springer 2020 年 9 月 16 日
Thank you so much! this fixed it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by