plotting using if statement... please help!!

1 visualización (últimos 30 días)
Sahrish Bajwa
Sahrish Bajwa el 1 de Mayo de 2021
Respondida: Jaynik el 3 de Abr. de 2024
hello,
I am trying to plot a graph with the if statement.
On the graph, x (time) should be 0 i.e. flatline (as current injected is -70 (y=-70)) when the current injected is higher than -70 (i.e. y = -69 to 40), then at that point an action potential graph is initiated (i.e. the rising phase of the graph begins). But i cannot seem to get the code to work.
Once the graph gets to 500 mS (x=500) then the flat line should come back again, just like at the beginning.
% Run simulation
sysPars.simTime = 500;
sysPars.odeopts = odeset('AbsTol',1e-8,'RelTol',1e-6);
[x,y] = ode45( @sysPars.model, [0 sysPars.simTime],...
modelPars.y0, sysPars.odeopts, modelPars);
if y<-60
x=0;
elseif x,y = ode45( @sysPars.model, [0 sysPars.simTime],...
modelPars.y0, sysPars.odeopts, modelPars);
end
% Plot results
figure(2);
plot(x, y(:,1),'Linewidth',1);
xlabel('Time (ms)','Fontsize',15);
ylabel('Voltage (mV)','Fontsize',15);
%xlim([0,sysPars.simTime]);
%xlim([-1.2 20])
set(gca,'Fontsize',15);
hold on;
%call table from excel sheet rtg4510 12 MO WT
t = readtable ('Single AP Traces_CA1PC.xlsx','sheet','rTg4510 12 MO CA1PC WT');
datasetAHP = 'CA1PCmonth12Tg.dat';
%select time and average columns w/ data
t(1:301,22:23);
%plot rtg4510 12MO WT excel
plot (t.Time_ms__1,t.AverageVm_mV_);
xlabel('Time (ms)','Fontsize',15);
ylabel('Voltage (mV)','Fontsize',15);
hold off
end
Once the graph gets to 500 mS (x=500) then the flat line should come back again, just like at the beginning.

Respuestas (1)

Jaynik
Jaynik el 3 de Abr. de 2024
Hi Sahrish,
For achieving the described behavior, the approach needs to be adjusted. The way in which if statements and the "ode45" function are used seems to be conceptually incorrect. The "ode45" function is used for solving ordinary differential equations and it is not clear how you have modelled the injected current or its effect on the system from the provided code snippet.
Instead of trying to manipulate the "x" and "y" directly, we can simulate the entire system first and then adjust the output for plotting based on the condition of the injected current.
Since the specifics of how the injected current is modeled or its relation to the action potential initiation are mpy provided, here is a conceptual code snippet regarding how to adjust the plotting based on a condition:
% Simulate the system (you will use ode45 or another method)
sysPars.simTime = 500;
x = linspace(0, sysPars.simTime, 1000); % Time vector
y = % Placeholder for the simulated voltage (replace with your actual simulation results)
% Define start and end of the action potential phase based on current injection
% Assuming the action potential starts at 100 ms and ends by 400 ms for illustration
apStartIndex = find(x >= 100, 1, 'first');
apEndIndex = find(x <= 400, 1, 'last');
% Simulate the action potential
for i = apStartIndex:apEndIndex
if x(i) < (x(apStartIndex) + x(apEndIndex)) / 2
% Rising phase
y(i) = y(i) - (x(i) - x(apStartIndex)); % Decrease to simulate the rise
else
% Falling phase
y(i) = y(i) - (x(apEndIndex) - x(i)); % Increase back to simulate the fall
end
end
% Ensure action potential is within -69 to 40 mV
y(apStartIndex:apEndIndex) = -69 + (40 - (-69)) * (y(apStartIndex:apEndIndex) - min(y(apStartIndex:apEndIndex))) / (max(y(apStartIndex:apEndIndex)) - min(y(apStartIndex:apEndIndex)));
% Plot results
figure;
plot(x, y, 'LineWidth', 1);
xlabel('Time (ms)', 'FontSize', 15);
ylabel('Voltage (mV)', 'FontSize', 15);
Hope this helps!

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by