2014-04-08 1 views
1

У меня есть файл excel, который содержит 2 тысячи раз по сравнению с наборами данных амплитуд. Время ячейка А и ячейка амплитуды В. Данные выглядит следующим образом:как печатать данные временной метки от excel от matlab

2/23/2012 3:12 -69,4

2/23/2012 3:13 -70,3

2/23/2012 3:14 -73,3

2/23/2012 3:15 -75,4

2/23/2012 3:16 -78,1

2/23/2012 3:17 -80,1

Как я могу построить значения амплитуды относительно метки времени в MATLAB?

ответ

0

Код

%%// FILENAME 
filename = 'sid.xls'; 

%%// OPTION 1: If there is a lot of data, XTickLaabels and XTicks would clutter up. 
%%// To Avoid that, define the number of XTickLabels needed, 
%%// otherwise set it as NaN to use all x-data. 
XTickLabel_count = 3; 

%%// OPTION 2: If you would like to show the time only with dates 
time_only = false; 

%%// OPTION 3: If you would like to show the XTickLabels as 90 degrees rotated 
XTickRot = false; 

%%// Read in data 
[num,text1,raw] = xlsread(filename); 

%%// Account for 12AM times, which are not read in text1. Append that data. 
split1 = regexp(text1,'\s','Split'); 
zero_times = cellfun(@numel, split1)==1; 
text1(cellfun(@numel, split1)==1) = mat2cell([char(text1(zero_times)) repmat(' 00:00:00',nnz(zero_times),1)],ones(1,nnz(zero_times))); 

%%// Get the time only data without dates 
split1 = regexp(text1,'\s','Split'); 
split_text = vertcat(split1{:}); 
time_text = split_text(:,2); 

%%// Use the time only data for XTickLabels 
if time_only 
    text1 = time_text; 
end 

%%// Select few XTickLabels from the entire X-data or whole respectively 
%%// and store as text2 
if ~isnan(XTickLabel_count) 
    XTickIntv = round(numel(text1)/XTickLabel_count); 
    text2 = cell(size(text1)); 
    text2(1:XTickIntv:end)=text1(1:XTickIntv:end); 
else 
    text2 = text1; 
end 

%%// Plot 
figure,plot(num) 
set(gca, 'XTickLabel',text2, 'XTick',1:numel(text2)) 
if XTickRot 
    xticklabel_rotate([],90,text2); 
end 
set(gca, 'Ticklength', [0 0]) %%// Remove XTicks but keep XTicklabels 

return; 

Примечание: Этот код использует XTICKLABEL_ROTATE from Mathworks File-exchange

подход 1: Использование XTickLabel_count = 3time_only = false и XTickRot = false

enter image description here

подход 2: Использование XTickLabel_count = 5time_only = true и XTickRot = false

enter image description here

Подход 3: Использование XTickLabel_count = 10time_only = true и XTickRot = true

enter image description here

+0

Привет, Когда я сюжет его в своей среде MATLAB Readi ng файл excel, я получаю это с вашего первого подхода: http://tinypic.com/view.php?pic=j8noqt&s=8#.U0SoA71lfDc см. сюжет, созданный темными линиями вместо отметки времени даты. Второй подход показывает следующее: http://tinypic.com/view.php?pic=15xqree&s=8 Посмотрите, что нет метки времени только для некоторых целых значений. Ваш третий подход показывает что-то вроде первого подхода + он также показывает сообщение об ошибке в строке: 4 В чем проблема? – user3511734

+0

Привет, Вот мой сырой файл excel. Можете ли вы рассказать мне, что проблема с заговором с вашим кодом? https://drive.google.com/file/d/0ByntE7ZqdSzoNkRhb0p3ckl0Mzg/edit?usp=sharing – user3511734

+0

@ user3511734 Проверьте отредактированные коды и убедитесь, что вы выбрали скрипт для поворота 'XTickLabels' из [здесь] (http://www.mathworks.in/matlabcentral/fileexchange/3486-xticklabelrotate) – Divakar

Смежные вопросы