clear;close all;clc
[~,~,raw]=xlsread('C:\Users\Administrator\Desktop\grace_study_record\数据可视化\matlab_动态图\example.csv');
names={'张三','李四','王二麻子'};
colors={[0,0,1],[0,1,0],[1,0,0]};
width=1; %每个条形的宽度
filename='test02.gif';
data_count=(size(raw,1)-1)/3; %%%一共多少天的数据
Fig=figure;
for index=1:data_count
AA=cell2mat(raw((index-1)*3+1+1,3));
BB=cell2mat(raw((index-1)*3+2+1,3));
CC=cell2mat(raw((index-1)*3+3+1,3));
data=[AA BB CC];
[data_sort,index_sort]=sort(data);
data_display=diag(data_sort);
colors_display={colors{index_sort(1)},colors{index_sort(2)},colors{index_sort(3)}};
names_display={names{index_sort(1)},names{index_sort(2)},names{index_sort(3)}};
b=barh(data_display,width);
for i=1:length(data)
b(i).FaceColor=cell2mat(colors_display(i));
end
set(gca,'yticklabel',names_display);
text(max(data)*0.9,1,raw((index-1)*3+1+1,4),'color','r','FontSize',14)
drawnow
frame=getframe(Fig);
im=frame2im(frame);
[imind,cm]=rgb2ind(im,256);
if index==1
imwrite(imind,cm,filename,'gif','WriteMode','overwrite','Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.02);
end
end
test02.gif
网友评论