MATLAB: Assignment has more non-singleton rhs dimensions than non-singleton subscripts

function [ Ts1] = ref1()
tf=30000;
h=1;
tf1=0:h:tf;
% Ts1
T_ref1=10*ones(30001,1);
for i=6001:12001
T_ref1(i)= (13/6000)*(i-1)-3;
end
for i=12002:18001
T_ref1(i)=23;
end
for i=18002:24001
T_ref1(i)=-(13/6000)*(i-1)+62;
end
% plot(tf1',T_ref1);
Ts1 = [tf1' T_ref1];
return
==
function [ Ts2] = ref2()
tf=30000;
h=1;
tf2=0:h:tf;
T_ref2=10*ones(30001,1);
for i=6001:12001
T_ref2(i)= (1/500)*(i-1)-2;
end
for i=12002:18001
T_ref2(i)=22;
end
for i=18002:24001
T_ref2(i) = -(1/500)*(i-1)+58;
end
% plot(tf2',T_ref2);
Ts2 = [tf2' T_ref2];
return
Ta=5;
dx(1,1) = 0.001*(-x(1)+Ta+0.01*x(3));
dx(2,1) = 0.001*(-x(2)+Ta+0.01*x(4));
Ts1=ref1;
Ts2=ref2;
f1 = (x(1)-Ts1)-ep*(1/x(3));
f2 = (x(2)-Ts2)-ep*(1/x(4));
f3 = -ep*(1/x(5));
dx(3,1) = G*(f3-f1);
dx(4,1) = G*(f3-f2);
dx(5,1) = G*(f1-f3 + f2-f3);
===
Assignment has more non-singleton rhs dimensions than
non-singleton subscripts
Error in xODE_v1 (line 26)
dx(3,1) = G*(f3-f1);
Could you please give me your advice to fix this error? Thank you so much.
Best regards,
Peter.

Best Answer

You have
f1 = (x(1)-Ts1)-ep*(1/x(3));
Ts1 is a vector so f1 is a vector
You then have
dx(3,1) = G*(f3-f1);
f1 is a vector so the right hand side is a vector. You are trying to store that entire vector into the single location dx(3,1)
Related Question