-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadFilesInNumericOrder.m
36 lines (33 loc) · 1.19 KB
/
loadFilesInNumericOrder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function [files,fileIndices,sortIndices] = loadFilesInNumericOrder(dirString,indexRegex)
files = dir(dirString);
files = {files.name};
fileIndices = cellfun(@(A) ternaryfun(isempty(A),@() NaN,@() str2double(A{1}{1})),cellfun(@(file) regexp(file,indexRegex,'tokens'),files,'UniformOutput',false));
files(isnan(fileIndices)) = [];
fileIndices(isnan(fileIndices)) = [];
[fileIndices,sortIndices] = sort(fileIndices);
files = files(sortIndices);
end
% mapping from index to location:-
%
% left
%
% +-+-+-+-+-+-+-+-+-+-+-+-+
% 0 | | | | | | | | | | | | | 11
% +-+-+-+-+-+-+-+-+-+-+-+-+
% 12 | | | | | | | | | | | | | 24
% +-+-+-+-+-+-+-+-+-+-+-+-+
% . . . . . . . . . . . . . .
% caudal . . . . . . . . . . . . . . rostral
% . . . . . . . . . . . . . .
% +-+-+-+-+-+-+-+-+-+-+-+-+
% 133 | | | | | | | | | | | | | 144
% +-+-+-+-+-+-+-+-+-+-+-+-+
%
% right
%
% 145 = thalamus
%
% hence to plot at 145 vector A as a motor map with left & right in the
% correct locations and rostral at the top is:
%
% imagesc(flipud(reshape(A(1:144),[12 12])))