File Exchange

image thumbnail

LVM file import

version 3.1 (6.01 KB) by

Imports LabView .lvm data files into MATLAB

64 Downloads

Updated

View License

National Instruments LabView software has a native file format called LabView Measurement File (LVM, extension .lvm). This m-file, lvm_import.m, reads LVM files and imports the data into the MATLAB workspace. lvm_import.m handles all types of text-based LVM files, and returns specific information such as date, time, data column names, etc.

Comments and Ratings (31)

Ahmet Sahinoz

Works perfectly in Matlab R2014b with the Labview data files we collected in wind tunnel tests.

Thanks man..

Lennart M

jeffery liu

Good share

Victor

Victor (view profile)

Hi

The function if a very slow when comma decimal separator is used. I changed the lines 439 to 454 for:

% create a format string for reading data as strings
fs = '%s'; for i=2:numdatacols, fs = [fs ' %s']; end %#ok<AGROW>
% add one more column for the comment field
fs = [fs ' %s'];
% Read columns as strings
rawdata = textscan(fid,fs,'delimiter',text_delimiter);
% Convert ',' decimal separator to '.' decimal separator
rawdata = cellfun(@(x) strrep(x,',','.'), rawdata, 'UniformOutput', false);
% Transform strings back to numbers
rawdata = cellfun(@(x) str2double(x), rawdata, 'UniformOutput', false);

Now, the function load the lvm file in less than 10 seconds instead of 180 seconds. Maybe you could introduce this modification.

Disclaimer: I only test the new code with a file of 8,8 MB with only one segment.

M. A. Hopcroft

M. A. Hopcroft (view profile)

I see some people are having trouble with this m-file; remember that I can't fix anything if you don't send me a bug report and some sample data... click on the author name above to contact me or find my email in the .m file. Thanks!

yasir hassan

Jim Browne

I am able to run this code successfully, but it returns no data. Just a 1x1 struct with the segment information. There is no "data" field.

M. A. Hopcroft

M. A. Hopcroft (view profile)

I have uploaded a new version with more fixes for comma-separated files and better overall performance. Thanks to @die-kenny for bug reports and testing and S. Danylenko for suggestions.

Giacomo

I use this code for my job: very useful, thanks a lot!

@ Sviatoslav Danylenko: I tried your modifications: very effective!

Hello, Hopcroft

If you want, you can increase speed of reading lvm files with non-dot decimal separator. It will be quick almost as reading of dot separated lvm files (speed difference is about 0.01-0.03 sec).

You need to replace this lines:
% handle case of not using periods (aka "dot" or ".") for decimal point separators
% (LVM version 2.0+)
if ~strcmp(data.Decimal_Separator,'.')
...
end

with this:

if ~strcmp(data.Decimal_Separator,'.')
if verbose >= 2, fprintf(1,'\n (using decimal separator "%s")\n',data.Decimal_Separator); end

valuesSource = fileread(filename);
valuesSource = strrep(valuesSource(ftell(fid):end), data.Decimal_Separator,'.');
else
valuesSource = fid;
end
% create a format string for reading data as numbers
fs = '%f'; for i=2:numdatacols, fs = [fs ' %f']; end %#ok<AGROW>
% add one more column for the comment field
fs = [fs ' %s']; %#ok<AGROW>
% read the data from file
[rawdata,position] = textscan(valuesSource,fs,'delimiter',text_delimiter);
% save first row comment as The Comment for this segment
data.(fieldnm).Comment = rawdata{size(rawdata,2)}{1};

if ~strcmp(data.Decimal_Separator,'.')
% fixing position in file
% we substituting one char more, that we actually need
% that extra char we will read at the next line. we use this to
% trigger eof flag for function feof()
fseek(fid, position-2, 'cof');
fscanf(fid, '%c');
end

Best Regards and Thanks for the lvm_import,
Sviatoslav

Si14

Si14 (view profile)

Adnan

Adnan (view profile)

when I downloaded this file a week before, it doesn't work for me. I just sent email to author, in reply I got very quick and brief solution. After couple of emails exchange, finally he sorted problem of

lvm_import('Data07v2.LVM');

Importing Data07v2.LVM:

??? Index exceeds matrix dimensions.

Error in ==> lvm_import at 164
val = v_in{1}{1};

for Labview prof 9.0.1 , NI scope 3.6 and Xp prof SP3.

Thanks for time and keep it up.

cheers

Adnan

Adnan (view profile)

M. A. Hopcroft

M. A. Hopcroft (view profile)

@Omar: good point. LabView creates an empty column with the label "X_Value" even if there is no X data in the file. The latest version of lvm_import ignores the label if there is no X data in the file.

Omar Mian

The first cell in data.Segment1.column_labels is always the string 'X_Value' regardless of whether or not there is a time column in the lvm file. Is this intended?

Omar Mian

I mean is this intended?

Andreas

The latest version of lvm_import works perfectly fine for me, the data is now doubles and not strings.

Thanks again for a great function!

M. A. Hopcroft

M. A. Hopcroft (view profile)

Thank you for all the feedback. There was a bug in lvm_import related to LVM files that use a comma as a decimal separator instead of a period, so that in files that use a comma, the data was returned as strings instead of numbers, as @Pedram and @Andreas experienced. That has been fixed in the latest version of lvm_import.

Andreas

Very nice program!

@Pedram: I encountered the same problem, but I managed to solve it. The problem is that when you've imported the data it is a cellstructure of strings. To be able to plot the data you need to convert it to a vector, e.g. by using the function str2num. I used the following command lines to import the data and convert it to a vector of doubles:

measurmentData = lvm_import(filename);
time = measurmentData.Segment1.data(:,1);
time = cellfun(@str2num,time)

Pedram

Pedram (view profile)

I managed to import my data but don't know how to plot them. any idea?

M. A. Hopcroft

M. A. Hopcroft (view profile)

Several people have reported problems where data cannot be imported. This may be related to LVM files that use a comma as a decimal separator instead of a period. This has been fixed in the latest version of lvm_import (and also in the NI LVM software).

Kenneth

Dear all,

Thanks for a great *.m file. I'm having a bit of trouble though, I'm trying to load a *.lvm file like this short 4KB example http://dl.dropbox.com/u/12840152/test18xy.lvm pretty standard 2011 *.lvm file I guess.

I) When I use the v1.2 lvm_import file as it is I get the same error as "Vepashka" above as "Error in ==> lvm_import at 357
data.(fieldnm).Comment = rawdata{numdatacols+2}{1};"

II) When I comment out the "consolidate into a simple array" part starting at line 349 and just keep the line 349 "data.data=rawdata" then I am able to complete the import

The only trouble with method II) is that my data.data struct is empty! Any help would be much appreciated as I'm struggling with my master thesis

Thanks,
Kenneth Rasmussen

M. A. Hopcroft

M. A. Hopcroft (view profile)

Note: the latest version (v1.2) uses the suggestions from Jo (13Jul2010), related to "Special" headers in the LVM file.

Jo

Jo (view profile)

Two bugs in the code that prevent it from working(possibly more) with some lvm files.

one is mulitple tabs. Changed line 178 to
v_in = textscan(linein,'%*s %s','delimiter','\t','whitespace','','MultipleDelimsAsOne', 1);

second is muliple lines: there is a check at line 237 for a single extra line but it should be more general skipping over all extra blank lines
---
for example, in my lvm the data had two tab's and two extra blank lines after the first header.
while (isempty(linein))
if (feof(fid)), return; end;
linein=fgetl(fid);
end;

To inform any future reference to this page, the updated file on 15 Apr 2010 worked fine with my problem mentioned above.

Hi,

Thanks for the file, but for my data it came up with the follwoing error message :

>> lvm_import('Data07v2.LVM');

Importing Data07v2.LVM:

??? Index exceeds matrix dimensions.

Error in ==> lvm_import at 164
val = v_in{1}{1};

Can you help me in this regard ?

Hi,

Thanks for the file, but for my data it came up with the follwoing error message :

>> lvm_import('Data07v2.LVM');

Importing Data07v2.LVM:

??? Index exceeds matrix dimensions.

Error in ==> lvm_import at 164
val = v_in{1}{1};

Can you help me in this regard ?

Vepashka

Sir im trying to import lvm file into matlab using ur lvm_import.m,that was acquired from some sensors.Im running the program but in each run i face with this problem.
"??? Index exceeds matrix dimensions.

Error in ==> lvm_import at 357
data.(fieldnm).Comment = rawdata{numdatacols+2}{1};"
What am i gonno do??Need a help,plsss!

Gerald Knebl

excellent programmed with good performance.
What I like to suggest is to make it compatible with multi x files as well.
really good work

Sung Jin Kim

very good

Updates

3.1

add graphic

3.1

v3.1 - More robust handling of files with missing data points. Fully vectorized processing of files using comma-separated decimals.

1.6

v2.2 fix for case of comma separator in multi-segment files; performance improvement

1.5

v2.1: fix "empty Separator" bug; align column labels with data array; other minor changes (see code comments for details)

1.4

v2.0: fix "string bug" for non-dot-based decimal files

1.3

Updated for LVM version 2.0 (decimal separator)

1.2

v1.2 bugfixes for "Special Headers".

1.1

v1.1 update to stay compatible with latest NI version

Added support for Multi-X column files
Added support for "no-header" files
Added per-Segment Comment extraction

MATLAB Release
MATLAB 8.6 (R2015b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video