Dimension 1 is fixed on the left-hand side but varies on the right ([1 x 1] ~= [:? x 1]).

7 Ansichten (letzte 30 Tage)
Good morning,
I'm writing a piece of code in a simulink block. Here the code
function [otv1, otv2, otv3] = TCU(P_tank1, P_tank2, P_tank3, time)
%% input
toll = 1; %[bar]
% coder.varsize('otv1');
% coder.varsize('otv2');
% coder.varsize('otv3');
persistent OTV1 OTV2 OTV3
if isempty(OTV1); OTV1 = 0; end
if isempty(OTV2); OTV2 = 0; end
if isempty(OTV3); OTV3 = 0; end
if time <= 0
OTV1 = 0;
OTV2 = 0;
OTV3 = 0;
else
Tank_unsorted =[P_tank1 OTV1
P_tank2 OTV2
P_tank3 OTV3];
% ordine decrescente di pressione
[Tank, index] = sortrows(Tank_unsorted, 'descend');
if (Tank(1,1) - Tank(2,1)) >= toll
Tank(1,2) = 1;
Tank(2,2) = 0;
Tank(3,2) = 0;
else if (Tank(1,1) - Tank(2,1)) < toll
Tank(1,2) = 1;
Tank(2,2) = 1;
Tank(3,2) = 0;
else if (Tank(2,1) - Tank(3,1)) <= toll
Tank(1,2) = 1;
Tank(2,2) = 1;
Tank(3,2) = 1;
end
end
end
end
index_otv = find(index == 1);
OTV1 = Tank(index_otv, 2);
index_otv = find(index == 2);
OTV2 = Tank(index_otv, 2);
index_otv = find(index == 3);
OTV3 = Tank(index_otv, 2);
%% output
otv1 = OTV1;
otv2 = OTV2;
otv3 = OTV3;
I tried the logic of the code in a script, and it works: OTVn in the end contains the correct scalar. But during the execution i have the error I wrote in the title at the lines
OTV1 = Tank(index_otv, 2);
and similar. But actually OTVn contains a scalar, because it's extracted from the matrix Tank.
I have tried the solutions on the net, but none of them worked (including coder.varsize). How could i overcome the problem? Considering the goal is to generate code

Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by