-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgif_maker.m
72 lines (72 loc) · 2.98 KB
/
gif_maker.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
clc, clear
close all
[x,y] = meshgrid(1:101,1:101);
maindir = input('输入路径:',"s");
data_name = input('输入数据名:','s');
subdir = dir(maindir);
for i = 1: length(subdir)
if( isequal( subdir( i ).name, '.' )||...
isequal( subdir( i ).name, '..')||...
~subdir( i ).isdir) % 如果不是目录则跳过
continue;
end
subdirpath = fullfile(maindir,subdir(i).name,'*.txt');
File = dir(subdirpath);
figure(1);
drawnow;
if ~isempty(File)
nname = File(1).name;
[keyword_l,keyword_r] = regexp(nname,"AMPA.*");
if isempty(keyword_l) || isempty(keyword_r)
[keyword_l,keyword_r] = regexp(nname,"GABA.*");
end
pic_name = erase(string(nname(keyword_l:keyword_r)),'.txt');
pic_index = 1;%记录图像编号
b = false;
if exist((string(maindir)+'\'+string(subdir(i).name)+'\'+'2000v'+pic_name+'.txt'),'file')
if b == false && pic_index < 5
File_name = string(2*pic_index)+'000'+data_name+pic_name+'.txt';
b = true;
else
File_name = string(pic_index)+'0000'+data_name+pic_name+'.txt';
b = false;
end
else
File_name = string(pic_index)+'0000'+data_name+pic_name+'.txt';
end
File_path = string(maindir)+'\'+string(subdir(i).name)+'\'+string(File_name);
gif_path = string(maindir)+'\'+string(subdir(i).name)+'\'+data_name+pic_name+'.gif';
%if exist(gif_path,'file') == 0
while ~exist(File_path,'file') == 0
data = importdata(File_path);
pcolor(x,y,data);
axis off
set(gcf,'unit','centimeters','position',[10 10 15 15])
set(gca,'Position',[0 0 1 1]);
F=getframe(gcf);
I=frame2im(F);
[I,map]=rgb2ind(I,256);
if pic_index == 1
imwrite(I,map,gif_path,'Loopcount',inf,'DelayTime',0.2);
else
imwrite(I,map,gif_path,'gif','WriteMode','append','DelayTime',0.2);
end
pic_path = erase(string(maindir)+'\'+string(subdir(i).name)+'\'+string(File_name),'.txt')+'.png';
%if exist(pic_path,'file') == 0
saveas(gcf, erase(string(maindir)+'\'+string(subdir(i).name)+'\'+string(File_name),'.txt')+'.png');
%end
pic_index = pic_index + 1;
if (b == true && pic_index < 5)
File_name = string(2*pic_index)+'000'+data_name+pic_name+'.txt';
if pic_index == 4
pic_index = 0;
b = false;
end
else
File_name = string(pic_index)+'0000'+data_name+pic_name+'.txt';
end
File_path = string(maindir)+'\'+string(subdir(i).name)+'\'+string(File_name);
end
%end
end
end