Borrar filtros
Borrar filtros

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.

8 visualizaciones (últimos 30 días)
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 in Phase_1LIGAND_INTERACTION>calculate_kf (line 75)
elseif t >= t_start && t < t_end
Error in Phase_1LIGAND_INTERACTION>@(t)calculate_kf(t,t_start,t_end,Kf1Max,Kf1Min,Kf1Tau_on,Kf1Tau_off) (line 23)
kf_1 = @(t) calculate_kf(t, t_start, t_end, Kf1Max, Kf1Min, Kf1Tau_on, Kf1Tau_off );
Error in Phase_1LIGAND_INTERACTION (line 61)
plot(t, kf_1(t), '-', 'LineWidth', 2);
get this error when during running code is given below
Phase_1LIGAND_INTERACTION()
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 in solution>calculate_kf (line 69)
elseif t >= t_start && t < t_end

Error in solution>@(t)calculate_kf(t,t_start,t_end,Kf1Max,Kf1Min,Kf1Tau_on,Kf1Tau_off) (line 24)
kf_1 = @(t) calculate_kf(t, t_start, t_end, Kf1Max, Kf1Min, Kf1Tau_on, Kf1Tau_off );

Error in solution>Phase_1LIGAND_INTERACTION (line 56)
plot(t, kf_1(t), '-', 'LineWidth', 2);
function Phase_1LIGAND_INTERACTION()
% Parameters
timespan = 0:0.01:100; % Time vector
Receptor_concentration = 100; % Concentration of Receptor
% Initial conditions
C_LigandReceptor_0 = 0; % Initial concentration of complex of ligand and receptor
% Time-dependent forward reaction rate constants (anonymous functions)
t_start = 5; % Start time of receptor pulse
t_end = 100; % Duration of receptor pulse
Kf1Max = 30;
Kf1Min = 1;
Kf1Tau_on = -1;
Kf1Tau_off = -0.5;
% Time-dependent backward reaction rate constants (anonymous functions)
Kb1Max = 20;
Kb1Min = 10;
Kb1Tau_on = -0.01;
Kb1Tau_off = -0.01;
kf_1 = @(t) calculate_kf(t, t_start, t_end, Kf1Max, Kf1Min, Kf1Tau_on, Kf1Tau_off );
kb_1 = @(t) calculate_kb(t, t_start, t_end, Kb1Max, Kb1Min, Kb1Tau_on, Kb1Tau_off );
% Solving the ODE system
[t, y] = ode45(@(t, y) ode_LR(t, y, kf_1, kb_1), timespan, [Receptor_concentration; C_LigandReceptor_0]);
% Extract the concentrations
receptor_concentration = y(:, 1);
ligand_Receptor_concentration = y(:, 2); % Now this represents the ligand-receptor complex concentration
% Calculate kf and kb values at each time point
kf_values = zeros(size(t));
kb_values = zeros(size(t));
kf_Tau_on_values = zeros(size(t));
kf_Tau_off_values = zeros(size(t));
kb_Tau_on_values = zeros(size(t));
kb_Tau_off_values = zeros(size(t));
for i = 1:length(t)
kf_values(i) = kf_1(t(i));
kb_values(i) = kb_1(t(i));
kf_Tau_on_values(i) = Kf1Tau_on;
kf_Tau_off_values(i) = Kf1Tau_off;
kb_Tau_on_values(i) = Kb1Tau_on;
kb_Tau_off_values(i) = Kb1Tau_off;
end
% Create a table for the data
data_table = table(t, kf_values, kb_values, kf_Tau_on_values,kf_Tau_off_values, kb_Tau_on_values,kb_Tau_off_values, timespan', ligand_Receptor_concentration, receptor_concentration, ...
'VariableNames', {'Time', 'kf', 'kb', 'kf_Tau_on', 'kf_Tau_off', 'kb_Tau_on','kb_Tau_off', 'TimeSpan', 'Ligand_Receptor_Concentration', 'Receptor_Concentration'});
% Write the data table to a CSV file
csv_filename = 'interaction_data.csv';
writetable(data_table, csv_filename);
% Plotting the results
figure;
plot(t, receptor_concentration, '-o', 'LineWidth', 2);
hold on;
plot(t, kf_1(t), '-', 'LineWidth', 2);
hold on;
plot(t, kb_1(t), 'o:', 'LineWidth', 3);
hold on;
plot(t, ligand_Receptor_concentration, '-k', 'LineWidth', 3);
hold on;
legend('Receptor', 'kf', 'kb' ,'Activated Receptor (Complex)');
end
function kf_1 = calculate_kf(t, t_start, t_end, Kf1Max, Kf1Min, Kf1Tau_on, Kf1Tau_off)
% Initial phase of the curve having a min value
if t < t_start
kf_1 = Kf1Min;
% Increasing phase from Min to Max
elseif t >= t_start && t < t_end
kf_1 = Kf1Max - (Kf1Max - Kf1Min) * exp(Kf1Tau_on * (t - t_start));
else % Decreasing phase from Max to Min
kf_end = Kf1Max - (Kf1Max - Kf1Min) * exp(Kf1Tau_on * (t_end - t_start));
kf_1 = Kf1Min + (kf_end - Kf1Min) * exp(Kf1Tau_off * (t - t_end));
end
end
function kb_1 = calculate_kb(t, t_start, t_end, Kb1Max, Kb1Min, Kb1Tau_on, Kb1Tau_off)
% Initial phase of the curve having a min value
if t < t_start
kb_1 = Kb1Min;
% Increasing phase from Min to Max
elseif t >= t_start && t < t_end
kb_1 = Kb1Max - (Kb1Max - Kb1Min) * exp(Kb1Tau_on * (t - t_start));
else % Decreasing phase from Max to Min
kb_end = Kb1Max - (Kb1Max - Kb1Min) * exp(Kb1Tau_on * (t_end - t_start));
kb_1 = Kb1Min + (kb_end - Kb1Min) * exp(Kb1Tau_off * (t - t_end));
end
end
function dydt = ode_LR(t, y, kf_1, kb_1)
% Unpack the concentrations
Receptor_concentration = y(1);
C_LigandReceptor = y(2);
% Define the ODE system
dReceptor_dt = -kf_1(t) * Receptor_concentration + kb_1(t) * C_LigandReceptor;
d_CLigandReceptor_dt = kf_1(t) * Receptor_concentration - kb_1(t) * C_LigandReceptor;
% Pack the derivatives into a column vector
dydt = [dReceptor_dt; d_CLigandReceptor_dt];
end

Respuestas (2)

Dyuman Joshi
Dyuman Joshi el 17 de Oct. de 2023
Double ampersand (&&) are only applicable when the output of each expression used for comparison is a scalar - Short-Circuit AND, &&.
However, you are comparing a vector to a scalar with an operation whose output is vector. Thus, you need to use single ampersand (&) symbol - and, & .
Also, note that the input to the if and the else statments you are using are vectors, thus the conditions will be checked upon the first value. Depending on what you are ocmparing, you might want to use any or all.

Walter Roberson
Walter Roberson el 17 de Oct. de 2023
[t, y] = ode45(@(t, y) ode_LR(t, y, kf_1, kb_1), timespan, [Receptor_concentration; C_LigandReceptor_0]);
The output t will be a vector.
plot(t, kf_1(t), '-', 'LineWidth', 2);
You are passing the vector to function kf_1
kf_1 = @(t) calculate_kf(t, t_start, t_end, Kf1Max, Kf1Min, Kf1Tau_on, Kf1Tau_off );
which passes it to function calculate_kf
elseif t >= t_start && t < t_end
which assumes that it is operating on scalar t.
You should vectorize your code using logical indexing https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html -- or you should use arrayfun() in kf_1 to ensure that you only pass a single t at a time to calculate_kf

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by