create a script that read mf4 files and plot each data without any toolbox in matlab

There is no easy way to read MF4 (Measure Files) in Matlab without a toolbox. However, we can read it using the Import Tool of Matlab. The Import Tool generates a code that can be used to import data from the file.

Here is an example of how to create a script that reads an MF4 file and plots each data. In this example, we assume the MF4 file is named data.mf4 and is located in the current folder.

main.m
% Open the Import Tool
importTool();

% Select the MF4 file to import and choose the data to be imported
% and the format to be used (table, timeseries, or matrix)
% Once done, generate code and copy it to the clipboard
% Close the Import Tool
% 
% Example code generated by the Import Tool:
% 
% % Import data from file
% filename = 'data.mf4';
% delimiter = ',';
% startRow = 1;
% formatSpec = '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';
% fileID = fopen(filename,'r');
% dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue' ,NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
% fclose(fileID);
% 
% % Convert to output type
% data = table(dataArray{1:end-1}, 'VariableNames', {'time','ID1','ID2','ID3','ID4','ID5','ID6','ID7','ID8','ID9','ID10','ID11','ID12','ID13','ID14','ID15','ID16','ID17','ID18','ID19','ID20','ID21','ID22','ID23','ID24','ID25','ID26','ID27','ID28','ID29','ID30','ID31','ID32','ID33','ID34','ID35','ID36','ID37','ID38','ID39','ID40','ID41','ID42','ID43','ID44','ID45','ID46','ID47','ID48','ID49','ID50','ID51','ID52','ID53','ID54','ID55','ID56','ID57','ID58','ID59','ID60','ID61','ID62','ID63','ID64','ID65','ID66','ID67','ID68','ID69','ID70','ID71','ID72','ID73','ID74','ID75','ID76','ID77','ID78','ID79','ID80','ID81','ID82','ID83','ID84','ID85','ID86','ID87','ID88','ID89','ID90','ID91','ID92','ID93','ID94','ID95','ID96','ID97','ID98','ID99','ID100','ID101','ID102','ID103','ID104','ID105','ID106','ID107','ID108','ID109','ID110','ID111','ID112','ID113','ID114','ID115','ID116','ID117','ID118','ID119','ID120','ID121','ID122','ID123','ID124','ID125','ID126','ID127','ID128'});
% 
% % Clear temporary variables
% clearvars filename delimiter startRow formatSpec fileID dataArray ans;

% Plot each data against time
time = data.time;  % the first column is time
for i=2:size(data,2)  % loop over each remaining column
    figure();
    plot(time, data{:,i}, '.');
    title(['Data ', num2str(i-1)]);
    xlabel('Time [s]');
    ylabel('Data');
end
2291 chars
35 lines

Note that the example code generated by the Import Tool may be different depending on the MF4 file used. In general, the code will read the MF4 file and convert it to a Matlab data type (table, timeseries, or matrix). We can then manipulate the data as we like and plot it.

related categories

gistlibby LogSnag