clc;
clear all;
data = importdata('E:\matlab\ouliter\5751-train.csv');
data = data.data;
%读取某一列
glucose = data(:,2);
%获得小数部分索引
[m,n] = find(glucose~=round(glucose));
%将连续是小数的数据以元胞数组形式保存
b = cell(0,0);
num = [];
ct = 1;
head = 1;
tail = 1;
while(ct<numel(m))
head = ct;
ct = ct+1;
while(ct<=numel(m)&&(m(ct)-m(ct-1))==1)
ct = ct+1;
end
tail = ct-1;
b = [b;m(head:1:tail)'];
num = [num; tail-head+1];
end
if(tail<numel(m))
b = [b;glucose(tail+1)'];
num = [num; 1];
end
%获取小数数据区域的总段数
[c,d] = size(b);
%先画出整体的图,然后利用hold on 将一段段的小数段用不同的颜色画上去
plot(glucose,'Color',[0.12 0.47 0.71],'LineWidth',1.5)
hold on
%对于小数部分的两端分别向外扩展一个数据,这样这条曲线都是小数部分了
for i = 1:1:c
bi = cell2mat(b(i));
[e,f] = size(bi);
if f == 1
bi = [bi-1,bi,bi+1];
end
plot(bi,glucose(bi),'Color',[1 0.5 0.05],'LineWidth',1.5);
% if length(cell2mat(b(i)))>1
hold on
end
set(gca,'XLim',[5337 7209],'linewidth',1.2); % X轴显示范围
set(gca,'XTick',[5337:288:7209]);%设计标签
set(gca,'XTickLabel',{'06','07','08','09','10','11','12'},'linewidth',1.2)% 设置坐标刻度
% set(gca,'XTickLabel',{'0h','2h','4h','6h','8h','10h','12h','14h','16h','18h','20h','22h','0h','2h','4h','6h','8h','10h','12h','14h','16h','18h','20h','22h','24h'})
% set(gca,'XLim',[0 288]); % X轴显示范围
% set(gca,'XTick',[0:24:288]); % 设置坐标刻度
% set(gca,'xtickslabels',{'0h','2h','4h','6h','8h','10h','12h','14h','16h','18h','20h','22h','24h'}
% xlabel('Time');
ylabel('Blood Glucose Leval');
title('575');
legend('Imputed','0riginal')
% 去掉图例边框
% legend('boxoff'); % 法1
% legend boxoff; % 法2
% % 关闭图像右上角边框
% box off
% 设置绘图外围颜色
set(gcf, 'Color', [1,1,1])
% fprintf('最长的连续数组是:\n')
% disp(b{max(num)==num})
使用matlab画图标记小数点部分为不同的颜色
最新推荐文章于 2022-12-18 23:28:42 发布