Comparing array elements of different lengths
조회 수: 5 (최근 30일)
이전 댓글 표시
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
Ameer Hamza
2020년 3월 7일
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?
답변 (1개)
Ameer Hamza
2020년 3월 7일
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Electrophysiology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!