Unable to perform assignment because the left and right sides have a different number of elements.

1 visualización (últimos 30 días)
Unable to perform assignment because the left and right sides have a different number of elements.
(line 93)
t_ar(step_counter)=t; % Add the current time to the time logclearvars
Does anyone know why I'm getting this error?
% Setup
t_max= 1200; % in s
k=0.01; % in s^-1
g_nr=2; % in molecules/s
t_nr=0; % in s
x_nr=5; % in molecules
step_counter=1;
% Perturbations
perturbation_magnitude=150; % in molecules
perturbation_time_400=400;% in s
perturbation_time_800=800;% in s
is_perturbation_400=0;
is_perturbation_800=0;
% Simulation of the non-regulated construct
t=0;
prod_rate=g_nr;
while t<t_max
deg_rate=k*x_nr(step_counter);
wait_time=-log(rand)/((prod_rate)+(deg_rate));
prob_prod=(prod_rate)/((prod_rate)+(deg_rate)); % Propensity of production
t=t+wait_time; % Update current time
step_counter=step_counter+1; % Update the number of steps (reactions) associated with the experiment.
t_nr(step_counter)=t; % Add the current time to the time log
if rand < prob_prod % Defines whether production takes place based on Monte Carlo method.
x_nr(step_counter)=x_nr(step_counter-1)+1; % Implements production
else
x_nr(step_counter)=x_nr(step_counter-1)-1; % Implements degradation
end
if t>perturbation_time_400 && is_perturbation_400==0
x_nr(step_counter)=x_nr(step_counter)+perturbation_magnitude;
is_perturbation_400=1;
end
if t > perturbation_time_800 && is_perturbation_800==0
x_nr(step_counter)=x_nr(step_counter)-perturbation_magnitude;
is_perturbation_800=1;
end
if t>t_max
t_nr(end)=[];
x_nr(end)=[];
end
end
close all
figure,
plot(t_nr,x_nr,'r','LineWidth',2)
hold on
% plot(x_nr,'b','LineWidth',2)
% legend('t_nr','x_nr')
% autoregulated construct
t_max= 1200; % in s
k=0.01; % in s^-1
step_counter=1;
t=0;
g_nr=2;
x_nr=5;
g_ar=4;
n_hill=8;
x_ar=5;
t_ar=0;
theta=(g_nr)/k;
% Perturbations
perturbation_magnitude=150; % in molecules
perturbation_time_400=400;% in s
perturbation_time_800=800;% in s
is_perturbation_400=0;
is_perturbation_800=0;
while t<t_max
prod_ratea=g_ar*((theta.^n_hill)./((theta.^n_hill)+(x_ar.^n_hill)));
deg_rate=k*x_ar(step_counter);
wait_time=-log(rand)./((prod_ratea)+(deg_rate));
prob_prod=prod_ratea/((prod_ratea)+(deg_rate)); % Propensity of production
t=t+wait_time; % Update current time
step_counter=step_counter+1; % Update the number of steps (reactions) associated with the experiment.
t_ar(step_counter)=t; % Add the current time to the time log
if rand < prob_prod % Defines whether production takes place based on Monte Carlo method.
x_ar(step_counter)=x_ar(step_counter-1)+1; % Implements production
else
x_ar(step_counter)=x_ar(step_counter-1)-1; % Implements degradation
end
if t>perturbation_time_400 && is_perturbation_400==0
x_ar(step_counter)=x_ar(step_counter)+perturbation_magnitude;
is_perturbation_400=1;
end
if t > perturbation_time_800 && is_perturbation_800==0
x_ar(step_counter)=x_ar(step_counter)-perturbation_magnitude;
is_perturbation_800=1;
end
if t>t_max
t_ar(end)=[];
x_ar(end)=[];
end
end
plot(t_ar,x_ar,'b','LineWidth',2)
% hold on
% plot(x_ar,'b','LineWidth',2)
legend('x_nr','x_ar')

Respuestas (1)

Image Analyst
Image Analyst el 7 de Jun. de 2022
Editada: Image Analyst el 7 de Jun. de 2022
t is not a scalar then. Just put a breakpoint there and see what the size of t is.
t is
t =
0.326275650711335 0.326275650711493
which can't fit into a single array element.
  3 comentarios
Kevin Holly
Kevin Holly el 7 de Jun. de 2022
t is 2x1 and not 1x1
I changed the code below to fix the error, however the solution may be wrong. You will need to check to see if the correct algorithm was performed.
% Setup
t_max= 1200; % in s
k=0.01; % in s^-1
g_nr=2; % in molecules/s
t_nr=0; % in s
x_nr=5; % in molecules
step_counter=1;
% Perturbations
perturbation_magnitude=150; % in molecules
perturbation_time_400=400;% in s
perturbation_time_800=800;% in s
is_perturbation_400=0;
is_perturbation_800=0;
% Simulation of the non-regulated construct
t=0;
prod_rate=g_nr;
while t<t_max
deg_rate=k*x_nr(step_counter);
wait_time=-log(rand)/((prod_rate)+(deg_rate));
prob_prod=(prod_rate)/((prod_rate)+(deg_rate)); % Propensity of production
t=t+wait_time; % Update current time
step_counter=step_counter+1; % Update the number of steps (reactions) associated with the experiment.
t_nr(step_counter)=t; % Add the current time to the time log
if rand < prob_prod % Defines whether production takes place based on Monte Carlo method.
x_nr(step_counter)=x_nr(step_counter-1)+1; % Implements production
else
x_nr(step_counter)=x_nr(step_counter-1)-1; % Implements degradation
end
if t>perturbation_time_400 && is_perturbation_400==0
x_nr(step_counter)=x_nr(step_counter)+perturbation_magnitude;
is_perturbation_400=1;
end
if t > perturbation_time_800 && is_perturbation_800==0
x_nr(step_counter)=x_nr(step_counter)-perturbation_magnitude;
is_perturbation_800=1;
end
if t>t_max
t_nr(end)=[];
x_nr(end)=[];
end
end
close all
figure,
plot(t_nr,x_nr,'r','LineWidth',2)
hold on
% plot(x_nr,'b','LineWidth',2)
% legend('t_nr','x_nr')
% autoregulated construct
t_max= 1200; % in s
k=0.01; % in s^-1
step_counter=1;
t=0;
g_nr=2;
x_nr=5;
g_ar=4;
n_hill=8;
x_ar=5;
t_ar=[];
theta=(g_nr)/k;
% Perturbations
perturbation_magnitude=150; % in molecules
perturbation_time_400=400;% in s
perturbation_time_800=800;% in s
is_perturbation_400=0;
is_perturbation_800=0;
while t<t_max
prod_ratea=g_ar*((theta.^n_hill)./((theta.^n_hill)+(x_ar.^n_hill)));
deg_rate=k*x_ar(step_counter);
wait_time=-log(rand(1))./((prod_ratea)+(deg_rate));
prob_prod=prod_ratea/((prod_ratea)+(deg_rate)); % Propensity of production
t=t+wait_time(1); % Update current time
step_counter=step_counter+1; % Update the number of steps (reactions) associated with the experiment.
t_ar(step_counter)=t; % Add the current time to the time log
if rand < prob_prod % Defines whether production takes place based on Monte Carlo method.
x_ar(step_counter)=x_ar(step_counter-1)+1; % Implements production
else
x_ar(step_counter)=x_ar(step_counter-1)-1; % Implements degradation
end
if t>perturbation_time_400 && is_perturbation_400==0
x_ar(step_counter)=x_ar(step_counter)+perturbation_magnitude;
is_perturbation_400=1;
end
if t > perturbation_time_800 && is_perturbation_800==0
x_ar(step_counter)=x_ar(step_counter)-perturbation_magnitude;
is_perturbation_800=1;
end
if t>t_max
t_ar(end)=[];
x_ar(end)=[];
end
end
plot(t_ar,x_ar,'b','LineWidth',2)
% hold on
% plot(x_ar,'b','LineWidth',2)
legend('x_nr','x_ar')

Iniciar sesión para comentar.

Categorías

Más información sobre Scripts en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by