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 vue (au cours des 30 derniers jours)
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Mai 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) ?
  1 commentaire
cindyawati cindyawati
cindyawati cindyawati le 8 Mai 2023
If I want to use dtbaru(j) how the code?
I already use dtbaru(j) but cannot show the plot. How to fix it?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by