Comparing array elements of different lengths

2 visualizzazioni (ultimi 30 giorni)
Graduate Student
Graduate Student il 6 Mar 2020
Risposto: Ameer Hamza il 7 Mar 2020
I'm trying to compare two arrays that are different lengths. One array will always be smaller than the other.
Array1 - stores pulses given
Array2 - stores neurons spiking information
I want to go through Array2 and match it the correct pulse in Array 1 and get the difference between the times (spike delay).
One way I've thought of is to have it go through Array2 and compare this value so that it falls in between two values in Array1.
So if Array2 has 2.6
Array1: .5 1.0 1.5 2.0 2.5 3.0
If would go through array 1 and then match between 2.5 and 3.0. Then it would subtract from the first value (2.5) to get the difference .1 and store in a different array.
For every time it doesn't match between numbers, I want it to count that which is the f_count. It would mean that the neuron did not spike.
true_spike = zeros(length(array2));
spike_delay = zeros(length(array2));
f_count = 0;
for i = 1:length(array2)
for j = 1:length(array1)
if array2(i,1) <= array1(j+1,1) && array2(i,1) > array1(j,1)
true_spike(i,1) = array2(i,1);
spike_delay(i,1) = array2(i,1) - array1(j,1);
else
f_count = f_count + 1;
end
end
end
spike_delay(spike_delay==0) = [];
spike_delay = spike_delay';
  4 Commenti
Ameer Hamza
Ameer Hamza il 7 Mar 2020
In your excel file, look at the cells D9 and D10. Is that a mistake? Both subtract B7 from A16 and A17. But B7 comes between A17 and A18, so shouldn't you only have A17-B7. Is this correct?
Graduate Student
Graduate Student il 7 Mar 2020
In column D I was manuallly calculating what I wanted Matlab to do.
Array 1 = pulses given
Array 2 = Neurons response
However, the neuron doesn't respond to each pulse. I was highlighting that in red for myself. I did subtract is twice to see the spike delay value. Given what I said above, it should be A17-B7, giving you -0.22. But actually that spike is responding to A16 giving you a value of -7.32. The reason for this is because -0.22 is too small of a value for the experiment. But for now I want to work on first getting column D and work on cases like B7 after.

Accedi per commentare.

Risposte (1)

Ameer Hamza
Ameer Hamza il 7 Mar 2020
The code gives the value according to the specified rule. The result matches with first few values in excel file
pulses = xlsread('Spiking_Example.xlsx', 'A:A');
neurons = xlsread('Spiking_Example.xlsx', 'B:B');
neurons(end) = []; % ignore last 0 in second column of excel file
difference = pulses - neurons';
mask = difference > 0;
[~, sub] = max(mask, [], 1);
sub = sub-1;
sub(sub==0) = size(difference,1);
index = sub2ind(size(difference), sub, 1:size(difference,2));
result = difference(index);

Categorie

Scopri di più su Electrophysiology in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by