Declare array in Simulink
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Guilherme Eichstadt
il 31 Gen 2018
Commentato: Birdman
il 31 Gen 2018
I have a function on Simulink that copy an in variable to another according a number (such as a DEMUX, but selectable)

% code
function [device,Var_RX1, Var_RX2, Var_RX3, Var_RX4, Var_RX5, Var_RX6, Var_RX7, Var_RX8, Var_RX9, Var_RX10] = fcn(device, Var_RX)
Var_RX1 = zeros(50,1,'single');
Var_RX2 = zeros(50,1,'single');
Var_RX3 = zeros(50,1,'single');
Var_RX4 = zeros(50,1,'single');
Var_RX5 = zeros(50,1,'single');
Var_RX6 = zeros(50,1,'single');
Var_RX7 = zeros(50,1,'single');
Var_RX8 = zeros(50,1,'single');
Var_RX9 = zeros(50,1,'single');
Var_RX10 = zeros(50,1,'single');
if (device == 1)
Var_RX1 = Var_RX;
elseif (device == 2)
Var_RX2 = Var_RX;
elseif (device == 3)
Var_RX3 = Var_RX;
elseif (device == 4)
Var_RX4 = Var_RX;
elseif (device == 5)
Var_RX5 = Var_RX;
elseif (device == 6)
Var_RX6 = Var_RX;
elseif (device == 7)
Var_RX7 = Var_RX;
elseif (device == 8)
Var_RX8 = Var_RX;
elseif (device == 9)
Var_RX9 = Var_RX;
elseif (device == 10)
Var_RX10 = Var_RX;
end
end
The problem is that when the function is call I have to declare the variables (Var_RX) as zeros otherwise the follow problem occurs: "Output argument 'Var_RX1' is not assigned on some execution paths."
There's a way to declare those arrays out this function and just start the value in the beginning of the program?
0 Commenti
Risposta accettata
Più risposte (1)
Birdman
il 31 Gen 2018
Modificato: Birdman
il 31 Gen 2018
Simulink does not like predefined outputs at the beginning because it wants to know the size of the output, or the maximum size it gets, so that it can allocate necessary space for it. Therefore you always need to specify the size of the output, and its value of course. There is no escaping from it. But be careful to not output a variable having bigger size than predefined. Otherwise it will also throw an error. To sum up, you always need to declare its(output) beginning value and size.
Hope this helps.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
