Outputting more than one value into Simulink system using Matlab function block

1 回表示 (過去 30 日間)
Bryan
Bryan 2019 年 7 月 6 日
回答済み: Nisar Ahmed 2020 年 5 月 6 日
Hi guys,
I have an issue with my matlab code. I am currently working on a solar MPPT system. I am using a Matlab function block for my algorithm which inputs the power from the solar PV and it will output the duty cycle according to my code. Currently, I wish to inject 4 duty cycles of 0.2, 0.4, 0.6, 0.8 one at a time and I need to save the power generated for each of these duty cycles. HOWEVER, my code is only able to output the first duty cycle. How do I code it to get it to run each duty cycle and to save the power generated for each of the duty cycle? For and while loops are not allowed in matlab function blocks cuz its a recursive call.
function D = BAT(P)
D = 0;
DPold = [0.2;0.4;0.6;0.8];
Pold = [0;0;0;0];
if D < 0.2
D = DPold(1);
Pold(1) = P;
elseif D < 0.4 & D >= 0.2
D = DPold(2);
Pold(2) = P;
elseif D < 0.6 & D >= 0.4
D = DPold(3);
Pold(3) = P;
elseif D < 0.8 & D >= 0.6
D = DPold(4);
Pold(4) = P;
else
end
Thanks guys!

回答 (2 件)

Raj
Raj 2019 年 7 月 8 日
There are two things here.
1) Your function code is wrong at many places. You will have to rewrite it:
function D = BAT(P) % So D is the output and P is the input
D = 0; % D is initlalized as zero
DPold = [0.2;0.4;0.6;0.8]; % fine
Pold = [0;0;0;0]; % fine
if D < 0.2 % condition will pass
D = DPold(1); % D=0.2
Pold(1) = P; % Polt(1)=whatever value of P you are giving
elseif D < 0.4 & D >= 0.2 % i think you meant D < 0.4 && D >= 0.2; condition pass
D = DPold(2); % D=0.4
Pold(2) = P;% Polt(2)=whatever value of P you are giving
elseif D < 0.6 & D >= 0.4 % i think you meant D < 0.6 && D >= 0.4; condition pass
D = DPold(3);% D=0.6
Pold(3) = P;% Polt(3)=whatever value of P you are giving
elseif D < 0.8 & D >= 0.6 % i think you meant D < 0.8 && D >= 0.6; condition pass
D = DPold(4);% D=0.8
Pold(4) = P;% Polt(4)=whatever value of P you are giving
else % not required
end
% function end missing here
%% so basically your function outputs D=0.8
2) I wish to inject 4 duty cycles of 0.2, 0.4, 0.6, 0.8 one at a time: First of all correct your function as i explained above so that you get an array D=[0.2,0.4,0.6,0.8] as output. Then you can use bus to transmit all the values at once to the next block.
  1 件のコメント
Bryan
Bryan 2019 年 7 月 10 日
Hi Raj.
Thanks for replying. I have edited my coded accordingly as you mentioned in the comment above. I am still getting an output of 0.2 only. Apart from that, would like to know if it is necessary to include a bus and also how do I go about it as my D has only one output from the function block.
Thanks!

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


Nisar Ahmed
Nisar Ahmed 2020 年 5 月 6 日
send me the code
nisark37@gmail.com

カテゴリ

Help Center および File ExchangeSolar Power についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by