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.

291 ビュー (過去 30 日間)
Jonathan Louie
Jonathan Louie 2022 年 6 月 7 日
編集済み: Matt J 2022 年 6 月 7 日
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.

回答 (2 件)

Image Analyst
Image Analyst 2022 年 6 月 7 日
>> 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 2022 年 6 月 7 日
編集済み: Matt J 2022 年 6 月 7 日
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?

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by