FileName = app.FilePath.Value;
FileNameLen = length(FileName);
if ~(strcmpi(FileName(FileNameLen-3:1:FileNameLen), '.mdf') || strcmpi(FileName(FileNameLen-3:1:FileNameLen), '.mf4'))
msgbox('无效mdf或mf4文件,请重新选择数据文件!');
读取并判断文件的有效性后,我们接下来就是读取所有需要的信号。我们将所有需要的信号以空格字符或“;”作为分隔符,将信号进行分割。如“SinusPhase0;SinusPhase90;SinusPhase180;SinusPhase270;”
%切割信号名序列
Variables = split(app.SignalName.Value, {' ',';'});
VariablesNum = length(Variables);
信号分割完成后,就是对各个信号进行罗列查找了。
VariableName(countFind) = read(app.DataFile, VariableNamei, char(Variables(i)), 'OutputFormat', 'timeseries');
为了了解到转换的进度,可通过添加数字进度,进行转换进度的展示。
%转换进度
percent = min(i/VariablesNum*100, 99);
percentStr = strcat(num2str(percent), '%');
app.StartMake.Text = strcat('转换进度:', percentStr);
所有信号查找完成后,需要将信号统一时间刻度,然后保存为mat格式。
eval(strcat(VariableName(i).Name, ' = interp1(VariableName(i).Time, VariableName(i).Data, t, ''linear'', ''extrap'');'));
save(char(DataName), VariableName(i).Name, '-append');
如果想要将所有缺失的信号展示出来,可通过如下代码实现。
通过以上主要的函数接口和代码,即可实现将mdf/mf4格式数据转换为mat格式。
如需具体代码,可留言联系。
应各位知友的要求,本帖将源代码贴上。
classdef CANape_DataFormat_Conversion < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
mdftomatUIFigure matlab.ui.Figure
FilePath matlab.ui.control.EditField
mdfmf4Label matlab.ui.control.Label
SelectFile matlab.ui.control.Button
StartMake matlab.ui.control.Button
Label_2 matlab.ui.control.Label
SignalName matlab.ui.control.TextArea
Lamp matlab.ui.control.Lamp
Label_3 matlab.ui.control.Label
signalPeriod matlab.ui.control.NumericEditField
msLabel matlab.ui.control.Label
properties (Access = public)
DataFile; % Description
methods (Access = private)
% Callback function: FilePath, SelectFile
function SelectA2LFile(app, event)
[FileName, PathName] = uigetfile('*.mf4;*.mdf', '选择一个mdf或mf4文件');
app.FilePath.Value = strcat(PathName, FileName);
app.DataFile = mdf(app.FilePath.Value);
% Button pushed function: StartMake
function StartMakeButtonPushed(app, event)
app.StartMake.Enable = 'off';
FileName = app.FilePath.Value;
FileNameLen = length(FileName);
if ~(strcmpi(FileName(FileNameLen-3:1:FileNameLen), '.mdf') || strcmpi(FileName(FileNameLen-3:1:FileNameLen), '.mf4'))
msgbox('无效mdf或mf4文件,请重新选择数据文件!');
app.Lamp.Color = [1,0,0];
%设定待保存文件名
FileNameSplit = split(app.FilePath.Value, '');
tempName = char(FileNameSplit(length(FileNameSplit)));
DataName = strcat(tempName(1:length(tempName)-4), '.mat');
%切割信号名序列
Variables = split(app.SignalName.Value, {' ',';'});
VariablesNum = length(Variables);
%逐个查找信号名并保存至文件
countMiss = 0;
countFind = 0;
for i = 1:VariablesNum
if strcmp(Variables(i), '')==0
flag = 0;
for VariableNamei = 1:length(app.DataFile.ChannelNames)
for VariableNamej = 1:length(app.DataFile.ChannelNames{VariableNamei})
if strcmp(Variables(i), app.DataFile.ChannelNames{VariableNamei}{VariableNamej})==1
flag = 1;
break;
if flag==1
break;
if VariableNamei==length(app.DataFile.ChannelNames) && flag==0
countMiss = countMiss + 1;
missVariable(countMiss) = i;
countFind = countFind + 1;
VariableName(countFind) = read(app.DataFile, VariableNamei, char(Variables(i)), 'OutputFormat', 'timeseries');
%转换进度
percent = min(i/VariablesNum*100, 99);
percentStr = strcat(num2str(percent), '%');
app.StartMake.Text = strcat('转换进度:', percentStr);
catch
countFind = countFind - 1;
countMiss = countMiss + 1;
missVariable(countMiss) = i;
% 数据统一时间
if countFind>0
if app.signalPeriod.Value/1000.0 > max(VariableName(1).Time)
msgbox('设定的信号周期超过了信号的最大时间,请重新设定合适的信号周期!');
return;
t = [0:app.signalPeriod.Value/1000.0:max(VariableName(1).Time)]';
save(char(DataName), 't');
for i = 1:countFind
eval(strcat(VariableName(i).Name, ' = interp1(VariableName(i).Time, VariableName(i).Data, t, ''linear'', ''extrap'');'));
save(char(DataName), VariableName(i).Name, '-append');
app.StartMake.Text = strcat('转换进度:', '100%');
if countMiss>=1
fid = fopen('missSignalName.txt','w');
fprintf(fid, '缺失的信号如下:');
fprintf(fid, 'n');
for i = 1:countMiss
fprintf(fid, char(Variables(missVariable(i))));
fprintf(fid, ';');
msgbox('该数据文件缺失部分信号,详见同目录下missSignalName.txt!');
msgbox('数据格式转换完成!');
app.StartMake.Text = '开始转换';
app.StartMake.Enable = 'on';
app.Lamp.Color = [0,1,0];
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create mdftomatUIFigure
app.mdftomatUIFigure = uifigure;
app.mdftomatUIFigure.Position = [100 100 640 480];
app.mdftomatUIFigure.Name = 'mdf to mat';
app.mdftomatUIFigure.Resize = 'off';
setAutoResize(app, app.mdftomatUIFigure, true)
% Create FilePath
app.FilePath = uieditfield(app.mdftomatUIFigure, 'text');
app.FilePath.ValueChangedFcn = createCallbackFcn(app, @SelectA2LFile, true);
app.FilePath.Position = [169 437 370 22];
% Create mdfmf4Label
app.mdfmf4Label = uilabel(app.mdftomatUIFigure);
app.mdfmf4Label.HorizontalAlignment = 'right';
app.mdfmf4Label.FontWeight = 'bold';
app.mdfmf4Label.Position = [17 441 153 15];
app.mdfmf4Label.Text = '待处理的mdf或mf4文件:';
% Create SelectFile
app.SelectFile = uibutton(app.mdftomatUIFigure, 'push');
app.SelectFile.ButtonPushedFcn = createCallbackFcn(app, @SelectA2LFile, true);
app.SelectFile.FontWeight = 'bold';
app.SelectFile.Position = [558 437 69 22];
app.SelectFile.Text = '选择';
% Create StartMake
app.StartMake = uibutton(app.mdftomatUIFigure, 'push');
app.StartMake.ButtonPushedFcn = createCallbackFcn(app, @StartMakeButtonPushed, true);
app.StartMake.FontSize = 14;
app.StartMake.FontWeight = 'bold';
app.StartMake.Position = [152 22 432 32];
app.StartMake.Text = '开始转换';
% Create Label_2
app.Label_2 = uilabel(app.mdftomatUIFigure);
app.Label_2.HorizontalAlignment = 'right';
app.Label_2.FontWeight = 'bold';
app.Label_2.Position = [17 402 109 15];
app.Label_2.Text = '待转换的信号名:';
% Create SignalName
app.SignalName = uitextarea(app.mdftomatUIFigure);
app.SignalName.Position = [27 70 600 323];
% Create Lamp
app.Lamp = uilamp(app.mdftomatUIFigure);
app.Lamp.Position = [596 28 20 20];
% Create Label_3
app.Label_3 = uilabel(app.mdftomatUIFigure);
app.Label_3.HorizontalAlignment = 'right';
app.Label_3.FontWeight = 'bold';
app.Label_3.Position = [17 31 57 15];
app.Label_3.Text = '信号周期';
% Create signalPeriod
app.signalPeriod = uieditfield(app.mdftomatUIFigure, 'numeric');
app.signalPeriod.Limits = [1 10000];
app.signalPeriod.Position = [76 27 37 22];
app.signalPeriod.Value = 5;
% Create msLabel
app.msLabel = uilabel(app.mdftomatUIFigure);
app.msLabel.Position = [116 31 25 15];
app.msLabel.Text = 'ms';
methods (Access = public)
% Construct app
function app = CANape_DataFormat_Conversion()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.mdftomatUIFigure)
if nargout == 0
clear app
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.mdftomatUIFigure)
1.该代码可用于标定或测试分析工作中,在测试结束,数据回灌时,可用于在matlab中读取MF4格式文件
2.读取之后,将MF4文件中包含的信号以及对应的数据返回到data结构体中,供后续使用。后期需要使用MF4文件中信号的,可以直接通过调用data结构体即可
(注:由于matlab处理数据的规则要求,读取的信号名称将实际测量中调用的信号名称中的 '.' 换成了 '_',其他没有任何处理)
https://blog.csdn.net/f7anty/article/details/44857557
1.select date(trim(char('2009-09-01 '))),time(trim(char('12:23:34 '))),timestamp(trim(char('2009-02-26-14.28.40.234000')))
from sysibm.dual
2....
(1)to_date("要转换的字符串","转换的格式") 两个参数的格式必须匹配,否则会报错。是将字符串转化为日期(DATE)格式,而且转化之后的格式与orcal系统日期参数有关(2)to_char(日期,"转换格式" ) 即把给定的日期按照“转换格式”转换知识点1:在使用Oracle的to_date函数来做日期转换时,很多Java程序员也许会直接的采用“yyyy-MM-dd HH:mm...
原公司用的数据库是Oracle和MySQL居多,写的SQL语句也比较少,有些生疏了。现在的公司使用的DB2数据库,完全没接触过,导致一些函数的使用要在网上搜索案例,现在总结一点DB2的函数使用方法。
正确需求:查询出指定日期的工作日,页面传一个天数,并返回一个新的日期。
下面是时间表字段:
刚开始项目需求说的不清楚,导致查询的结果不对,原来的需求只是说过滤掉周六周日休息时间和周一至周五...
由于上下班时间距离较远,小编一般会提前下载一些视频路上看,但是有的视频格式不是手机能播放的,需要转换格式才行,比如优酷视频就是kux格式,需要转换成MP4才行。今天就聊聊格式转换心得,这两种方法一定得会。 方法一:金舟视频格式转换器 第一步,打开金舟视频格式转换器进入主页,点击“添加文件”,将已经下载好的优酷视频文件添加进来。 第二步,点击右下角“选择格式”,然后在弹出的选择对话框中选...
大数据时代的网络到处堆积着数据,自由生长,没有标准,即使是一个日期,就有好几种格式。比如某个网站有一年内的美元人民币汇率历史数据(已下载成excel文件,用pd.read_excel语句转成dataframe),日期的格式如图一: data = pd.read_excel('美元人民币.xlsx', sheet_name='HistoryExchangeReport')
data = data[[...