Declare array in Simulink
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Guilherme Eichstadt
el 31 de En. de 2018
Comentada: Birdman
el 31 de En. de 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 comentarios
Respuesta aceptada
Más respuestas (1)
Birdman
el 31 de En. de 2018
Editada: Birdman
el 31 de En. de 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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
