Effacer les filtres
Effacer les filtres

Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.

110 vues (au cours des 30 derniers jours)
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to
reduce operands to logical scalar values.
Error (line 100)
if t>perturbation_time_400 && is_perturbation_400==0
Does anyone know why this error is happening?
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;
wait_time=-log(rand)./((prod_ratea)+(deg_rate(step_counter)));
prob_prod=prod_ratea./((prod_ratea)+(deg_rate(step_counter))); % 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 =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
end
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.

Réponses (2)

Image Analyst
Image Analyst le 7 Juin 2022
>> perturbation_time_400
perturbation_time_400 =
400
>> is_perturbation_400
is_perturbation_400 =
0
>> t
t =
0.829087583945347 0.829087583945508
So, which element of t do you want to compare to perturbation_time_800? t(1) or t(2) or any of them or all of them?

Matt J
Matt J le 7 Juin 2022
Modifié(e) : Matt J le 7 Juin 2022
As you can see from the debugger screenshot your t does not remain a scalar as your code loops. Is that supposed to happen, and if so how would you like the if statement to handle that?

Catégories

En savoir plus sur Shifting and Sorting Matrices 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