How to save a matrix to be able to use it in another m file

7 次查看(过去 30 天)
Hi there!
I have a m file which should create a 1x1000001 matrix (called RM03input1to1) of 1s and zeros (depending on the condition in the for loop). I'd like to somehow save that vector somewhere on my computer, then access that same vector (RM03input1to1) in another m file later. Here's my first m file that creates the vector:
function[isi] = OneNeuronFiring(frequency, dtPass, DPass, Amplitude)
tfin = 10000; %Final time value, in seconds
dt = dtPass; %timestep
vth = 1; %threshold voltage (once the neuron reaches this voltage, it fires)
vr = 0; %The reset voltage is 0 (after the neuron fires, its voltage goes back down to 0)
lif1data = []; %array of spike times (when the neuron fires) and relative spike time differences (time between 2 consecituve spike times)
tau = 1; %membrane time constant
A = Amplitude; %sinusoidal stimulus term (intensity of the dyad inputs)
vinit = 0; %voltage initial condition (starts at 0)
tlast = 0; %initialize last firing times
rads = frequency;
v = vinit;
D = DPass;
I = 0.9; %units of current divided by capacitance (bias to the cells. This gives a kick to the cells as they're reaching threshold voltage.)
a = 1;
b = 1;
RM03input1to1 = zeros(size(0:dt:tfin));
itercount = 1;
%main loop (LIF voltage change is measured, then the noise is added to the previous voltage)
for t=0:dt:tfin
noise = sqrt(2*D*dt)*randn();
dv = -v/tau + I*(1 + A*cos(a*rads*t) + A*cos(b*rads*t));
v = v + dt*dv + noise;
if (v >= vth)
tlast = t;
v = vr;
lif1data = [lif1data; t];
end
if (v >= vth)
RM03input1to1(itercount) = 1;
itercount = itercount + 1;
else
itercount = itercount + 1;
end
end
isi = diff(lif1data); %difference between consecutive spike times
any help on this would be greatly appreciated!

采纳的回答

Sriram Tadavarty
Sriram Tadavarty 2020-3-16
Hi Olivia,
You can use save and load functions for this purpose.
In the function, use save('RM03Input',RM03input1to1) % first argument is the file name, second argument is the variable name
This will create a mat file with name RM03Input in the working folder.
The variables from this mat file can be accessed from another function by loading the mat file.
function temp
load('RM03Input.mat')
i = RM03inpt1to1(1);
end
Here are the documentation links which provide more details about the usage:
Hope this helps.
Regards,
Sriram

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Electrophysiology 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by