Hello, I get error "Unable to perform assignment because the left and right sides have a different number of elements". How to fix this?

1 visualizzazione (ultimi 30 giorni)
K1= 10^-6;
K2=5*10^-6;
K3=10^-5;
delta=50;
Oa=10;
Pa=100;
Ko=0.1;
mu_1=10^-3;
gamma=75;
m1=10;
n=3;
K=0;
M=0;
h=0.5;
dt=0:h:100; %time scale
dtbaru=dt';
M1=zeros(length(dtbaru),1); %empty array for M1
M2=zeros(length(dtbaru),1); %empty array for M2
M3=zeros(length(dtbaru),1); %empty array for M3
Ki=zeros(length(n-1),1);
for j= 1:length(M1)
M1=1./(1+exp(dtbaru(j)+6)); %sigmoid equation
end
for i=1:length(Ki)
K(i+1)=K(i);
end
for j = 1:length(dtbaru)
M1(j) = M1(j)+dtbaru*[delta*M1(j)*[1-(M1(j)/gamma)]-2*K1*M1(j)*M1(j)-M1(j)*(K(i).*M(j))-(Oa-n)*K3*M1(j)*M3(j)-(Pa-Oa)*Ko*M1(j)*10-(mu_1*M1(j))];
end
Unable to perform assignment because the left and right sides have a different number of elements.

Risposta accettata

Walter Roberson
Walter Roberson il 7 Mag 2023
dt=0:h:100; %time scale
Row vector
dtbaru=dt';
Column vector.
for j = 1:length(dtbaru)
M1(j) = M1(j)+dtbaru*[delta*M1(j)*[1-(M1(j)/gamma)]-2*K1*M1(j)*M1(j)-M1(j)*(K(i).*M(j))-(Oa-n)*K3*M1(j)*M3(j)-(Pa-Oa)*Ko*M1(j)*10-(mu_1*M1(j))];
The loop is iterating j over the length of dtbaru, but the assignment to M1(j) uses all of dtbaru in the calculation and so gives a column-vector result that is not going to fit into the single location M1(j)
Perhaps you wanted to use dtbaru(j) ?

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by