Problem in a M-file (actualized)

1 view (last 30 days)
Avelino
Avelino on 3 Nov 2011
Hello,
Maybe this question will sound really rookie, but there is a long time since I don't work with MatLab. Well, I am trying to design one M.file, that allows me to calculate the reliability of the neuron. First I will explain the problem and then I will show my solution and my doubts about how to make it. In this way, I have my data, which can be divided for something like 300 trials (when we repeated the stimuli). So, we repeteaded the stimuli 300 times. I have data with the start and the end of each stimulus, let's give it as example:
Time Marker
0.02 0 Starts the stimulus (Trial#1)
0.8 0
1.4 0
(...)
16 1 Finish the stimulus
16.5 0 Starts a new stimulus (Trial#2)
In this way, I wanted to isolate the times when the stimulus finish and starts again, to know where each trial begins and starts. In practice this means to take the time when the marker is 1 and the next after 1, when is 0. After having this, I wanted to have a matrix with 300 lines (trials) and the number of columns like t(stimulus start):bin (defined for the person using the function):t(stimulus finish). After having this matrix, I have also the data where I have the spikes. If the spike happened in the interval between each bin, I want the vector with 1, if not, I want with 0. Let's say: that i is the number of lines (300) and j is the number of columns (length/bin)
A(i,j)= 0.02 0.04 0.06 () 16 (First trial)
If we have the spikes like
0.02 0.021 0.03 0.07
I want that the vector have:
v(i,j-1) = [1 0 () ]
With this, I just want to multiply and sum the vectors along the lines, divided for the trials.
What I did in MatLab, it was something like this:
function [R] = reliab(marker1, marker2, spike, bin)
%Reliability function: Calculates the reliability (from 0 to 1), to a
%neuron spike to the same stimulus
% Marker 1 - Means to the time where the stimulus finish
% Marker 2 - Means to the time where the stimulus begin
% Marker 1-Marker 2 : Spontaneous activity of the cell
% bin - space to count the spikes in one trial
% spike - spikes along the trials
% b: vector with the times where the stimulus is finishing
% a: vector with the times where the stimulus is beginning
% Size of a and b: number of trials
% A matrix with the number of lines equal to number of trials and columns
% equal to the bin summed sucessively to the time where the stimulus has
% started, till reach the end of stimlus
% v(n, m-1) - spike train vector: if the spike occured in the trial n,
% between m and m+1, 1, if not 0.
% Reliability compares the sucess or non-sucess of the neuron spiking after
% the other in the same bin.
B = 0;
b = marker1.*marker2;
b(ismember(bi, B, 'rows'), :) = [];
for l=1:length(marker1)
for m=1:length(marker2)-1
a = marker1(l+1).*marker2;
end
end
a(ismember(a, B, 'rows'), :) = [];
A = bsxfun(@plus, a, 0:bin:b);
[n, m] = size(A);
for i =1:n
for j=1:m
for k=1:length(spike)
if spk(k,1)>=A(n,m) && spk(k,1)<=A(n,m+1)
v(n, m-1) = 1;
else
v(n, m-1) = 0;
end
end
end
end
R = sum((v(n,m).*v(n+1,m))/(abs(v(n,m))*abs(v(n+1,m))))*(2/(n(n-1)));
end
My problem is that MatLab is giving me errors and I tried everything, but I cannot figure it out, if somebody could help me, I really would appreciate.
The errors that are showed in Matlab so far, are these:
Error in ==> reliab at 21
b = marker1.*marker2;
  • And also there is a warning message advicing to preallocate the vector v (Line 34), but in this case I do not know how to make it.
Thank you in advance once again!
Avelino
[EDITED, Jan Simon, 03Nov2011 11:54UTC, Code formatting improved]
[EDITED, Jan Simon, 03Nov2011 13:19UTC, Code formatting improved again]
  3 Comments
Avelino
Avelino on 3 Nov 2011
Yes, you were right. I hope that now it could be better, I changed the code as well :)
Thank you!
Jan
Jan on 3 Nov 2011
The loops look strange, because the do not depend on the output loop counters. There it is not clear, what you wnt to achieve.

Sign in to comment.

Answers (1)

Jan
Jan on 3 Nov 2011
  • It seems like marker1 and marker2 do not have the same dimensions.
  • In the next line the variable bi is not defined - I assume you mean bin.
  • b(ismember(bi, B, 'rows'), :) = [] is not efficient. I assume you want:
b = b(all(b, 2), :);
But the dimensions of b are not clear. Mayby this is enough:
b = b(b~=0);
  • You overwrite the value of a in each iteration. Is this intented? For a(ismember(a, B, 'rows'), :)=[] see above.
  • In the look over k you overwrite the value of v(n, m-1) ineach iteration. I assume this is not wanted.
  • bsxfun(@ge, spk(k,1), A(i,j)) && bsxfun(@le, spk(k,1), A(i,j+1)) is not useful for scalars. Nicer and faster:
if spk(k,1)>=A(i,j) && spk(k,1)<=A(i,j+1)
  • i(i-1) is not a valid Matlab expression. Do you mean i*(i-1) ?
  1 Comment
Avelino
Avelino on 3 Nov 2011
Hello, thank you for your answer.
The dimensions of marker1 and marker2 will be the same in the data that I will have the input;
In the case of B, I will multiply marker1 and marker2. The numbers in marker2 are just between 0 and 1 and consequently with this: b(ismember(bi, B, 'rows'), :) = [], I wanted to delete the rows which are 0. For a, the idea it is the same, to delete the values that are zero, after the multiplication.
About v(n, m-1), my intention is to compare the matrix that is the input spike with the A(i, j) and A(i,j+1), if the value is inside, I want that in this place shows 1.
Thank you very much for the advices, somethings are already clear to me :)

Sign in to comment.

Categories

Find more on Electrophysiology in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!