从文本文件中创建图形,其中轴X是具有毫秒精度的日期,并且Y是具有标记的值 [英] creating graph from text file where axis X is date with millisecond precision and Y is value with markers
问题描述
我仍然无法在matlab中创建可用的东西。
这个任务非常简单。我有两个文件:
那么我的任务非常简单直接。 matlab中有简单而直接的解决方案吗?上面的代码已经包含了几个黑客,但仍然无法按预期工作。我害怕挫败黑客没有意义。有人会提出另一种方法吗?可能matlab只是不适合我的需要?
- 下载 $ / $> $ / $> $ / $> $ / $> $ / $> $ / $> $ / $>
set(gca,'YTickLabel',get( gca,'YTick'))
datetick('x','HH:MM:SS');
-
将它们替换为
ticklabelformat(gca,'y','%g')
ticklabelformat(gca,'x',{@ tick2datestr,'x','HH:MM:SS'} )
-
创建一个新的帮助函数
tick2datestr.m
包含:
函数tick2datestr(hProp,eventData,axName,dateformat)%#ok< INUSL>
hAxes = eventData.AffectedObject;
tickValues = get(hAxes,[axName'Tick']);
tickLabels = arrayfun(@(x)datestr(x,dateformat),tickValues,'UniformOutput',false);
set(hAxes,[axName'TickLabel'],tickLabels);
end
功能是BTW复制直接出ticklabelformat。
是的,你可以认为这是黑客攻击,但只要TheMathworks doesn' t实现你想要的'直接'解决方案,你必须创建自己的功能。
I still can not create something usable in matlab.
The task is pretty simple. I have two files: devideHistory.log deals.log In both files lets consider only first two column. So first file contains X and Y which should form graphic. Second file contains X and Y of markers that should be displayed on the graphic. With help of this community such program was created
clear
fDevide = fopen('devideHistory.log');
data = textscan(fDevide, '%f:%f:%f:%f %f,%f %f,%f');
fclose(fDevide);
% hh:min:sec:millisec
secvec = [60*60 60 1 1e-3];
x = [data{1:4}] * secvec';
flvec = [1 1e-16];
y = [data{5:6}] * flvec';
xindays = x / (24*60*60);
plot(xindays, y);
% set(gca, 'YTickLabel', get(gca,'YTick'))
% datetick('x', 'HH:MM:SS');
hold on
fDeals = fopen('deals.log');
data = textscan(fDeals, '%f:%f:%f:%f %f,%f %f,%f %f,%f %f');
fclose(fDeals);
% hh:min:sec:millisec
secvec = [60*60 60 1 1e-3];
x = [data{1:4}] * secvec';
flvec = [1 1e-16];
y = [data{5:6}] * flvec';
xindays = x / (24*60*60);
plot(xindays, y, 'go','MarkerSize',6,'LineWidth',3);
% i need to set enough precision on Y but this doesn't work because
% while zooming labels doesn't update
set(gca, 'YTickLabel', get(gca,'YTick'))
% i want to have "time" on X but this doesn't work because
% while zooming new labels doesn't appear
datetick('x', 'HH:MM:SS');
Result:
But I have two problems with zooming feature:
- while zooming in labels from X disappear and as a result there are not labels at X at all how to always display "labels" on axis X
- while zooming labels on Y is not updated as a result markers are displayed on the wrong position why while zooming marker changes position?
Well my task is pretty simple and straightforward. Are there simple and straightforward solution in matlab for it? Code above already contains several "hacks" and still doesn't work as expected. I'm afraid contining hacking it doesn't make sense. Could someone suggest another approach? Probably matlab just not suitable for my needs?
- Download http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat
Remove your own tick labeling calls, these ones:
set(gca, 'YTickLabel', get(gca,'YTick')) datetick('x', 'HH:MM:SS');
Replace them with
ticklabelformat(gca,'y','%g') ticklabelformat(gca,'x',{@tick2datestr,'x','HH:MM:SS'})
Make a new helper function
tick2datestr.m
containing:function tick2datestr(hProp,eventData,axName,dateformat) %#ok<INUSL> hAxes = eventData.AffectedObject; tickValues = get(hAxes,[axName 'Tick']); tickLabels = arrayfun(@(x)datestr(x,dateformat),tickValues,'UniformOutput',false); set(hAxes,[axName 'TickLabel'],tickLabels); end
most of this helper function is btw copied straight out of ticklabelformat.
Yes, you can consider this as hacking, but as long as TheMathworks doesn't implement your desired 'straightforward' solution, you have to create your own functionality.
这篇关于从文本文件中创建图形,其中轴X是具有毫秒精度的日期,并且Y是具有标记的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!