Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
read labview files in matlab.

Subject: read labview files in matlab.

From: Neet Lad

Date: 25 Nov, 2010 13:25:04

Message: 1 of 8

Good afternoon all.

i have saved two different waveform data into an array and used the vi' to create 2 colums of 4000 rows. each column is headed with string. The data is tab deliminated and the header is split from the data by a carriage return.

Is there a way to write the array in a format which can be simply loaded into matlab.
i can, but do not want to import the .txt and save the .mat file and then call on the mat file, since i will be saving many files over 200 for each test. each with a new header.

when loading into matlab i would like to treat the two waveforms in the 4000x2 array as 2 column vectors (each column is an independant data set).

is there a way to do this ?

kind regards.

Neetin Lad

Subject: read labview files in matlab.

From: Rune Allnor

Date: 25 Nov, 2010 14:18:05

Message: 2 of 8

On Nov 25, 2:25 pm, "Neet Lad" <nits...@hotmail.com> wrote:
> Good afternoon all.
>
> i have saved two different waveform data into an array and used the vi' to create 2 colums of 4000 rows.  each column is headed with string.  The data is tab deliminated and the header is split from the data by a carriage return.  
>
> Is there a way to write the array in a format which can be simply loaded into matlab.  
> i can, but do not want to import the .txt and save the .mat file and then call on the mat file, since i will be saving many files over 200 for each test. each with a new header.

The easiest way is to save a .txt file and load it into matlab.

> when loading into matlab i would like to treat the two waveforms in the 4000x2 array as 2 column vectors (each column is an independant data set).  
>
> is there a way to do this ?

Sure.

TEXTSCAN or DLMREAD might be useful if you don't want to
roll your own.

Rune

Subject: read labview files in matlab.

From: Andres

Date: 25 Nov, 2010 22:03:03

Message: 3 of 8

"Neet Lad" <nits_76@hotmail.com> wrote in message <iclo3g$ovl$1@fred.mathworks.com>...
> [..]
> Is there a way to write the array in a format which can be simply loaded into matlab.
> [..]

Did you check out any of these file exchange submissions?

http://www.mathworks.com/matlabcentral/fileexchange/?term=labview

Subject: read labview files in matlab.

From: Neet Lad

Date: 26 Nov, 2010 11:13:04

Message: 4 of 8

"Andres" <rantore@werb.deNoRs> wrote in message <icmmen$qau$1@fred.mathworks.com>...
> "Neet Lad" <nits_76@hotmail.com> wrote in message <iclo3g$ovl$1@fred.mathworks.com>...
> > [..]
> > Is there a way to write the array in a format which can be simply loaded into matlab.
> > [..]
>
> Did you check out any of these file exchange submissions?
>
> http://www.mathworks.com/matlabcentral/fileexchange/?term=labview

yes but i my understanding of matlab is very basic and i couldnt find exactly what i wanted. at the moment i am using :

function importfile(fileToRead)
% Import the file
newData1 = importdata('d0000x050.ascii');

% Break the data up into a new structure with one field per column.
colheaders = genvarname(newData1.colheaders);
for i = 1:length(colheaders)
    dataByColumn1.(colheaders{i}) = newData1.data(:, i);
end

% Create new variables in the base workspace from those fields.
vars = fieldnames(dataByColumn1);
for i = 1:length(vars)
    assignin('base', vars{i}, dataByColumn1.(vars{i}));
end

i think if i can put in a for loop at the begining to read a file in the directory at a time. using something like below.

files=dir('*.ascii')
for k=1:length(files)

is this possible?

thank you for your posts.

Subject: read labview files in matlab.

From: Mark Shore

Date: 26 Nov, 2010 12:57:04

Message: 5 of 8

>
> i think if i can put in a for loop at the begining to read a file in the directory at a time. using something like below.
>
> files=dir('*.ascii')
> for k=1:length(files)
>
> is this possible?
>

Sure.

files = dir('*.ascii');
  for k = 1:length(files)
    currentFileName = files(k).name; % extract file name from struct
    % your code goes here
  end

Subject: read labview files in matlab.

From: Neet Lad

Date: 26 Nov, 2010 13:26:04

Message: 6 of 8

Thanks for the post however when using :

files = dir('*.ascii');
  for k = 1:length(files)
      currentFileName = files(k).name; % extract file name from struct
function importfile(fileToRead)
% Import the file
    newData1 = importdata('d0000x050.ascii');

% Break the data up into a new structure with one field per column.
colheaders = genvarname(newData1.colheaders);
for i = 1:length(colheaders)
    dataByColumn1.(colheaders{i}) = newData1.data(:, i);
end

 
% Create new variables in the base workspace from those fields.
vars = fieldnames(dataByColumn1);
for i = 1:length(vars)
    assignin('base', vars{i}, dataByColumn1.(vars{i}));
end
end

i get an error:

??? Error: File: tmp.m Line: 5 Column: 1
Function definitions are not permitted at the prompt or in scripts.

also where i have importdata('filename') should this be importdata(files(k))

knd regards
Neetin Lad.

Subject: read labview files in matlab.

From: Mark Shore

Date: 26 Nov, 2010 15:44:05

Message: 7 of 8

"Neet Lad" <nits_76@hotmail.com> wrote in message <icochb$ave$1@fred.mathworks.com>...
> Thanks for the post however when using :
>
> files = dir('*.ascii');
> for k = 1:length(files)
> currentFileName = files(k).name; % extract file name from struct
> function importfile(fileToRead)
> % Import the file
> newData1 = importdata('d0000x050.ascii');
>
> % Break the data up into a new structure with one field per column.
> colheaders = genvarname(newData1.colheaders);
> for i = 1:length(colheaders)
> dataByColumn1.(colheaders{i}) = newData1.data(:, i);
> end
>
>
> % Create new variables in the base workspace from those fields.
> vars = fieldnames(dataByColumn1);
> for i = 1:length(vars)
> assignin('base', vars{i}, dataByColumn1.(vars{i}));
> end
> end
>
> i get an error:
>
> ??? Error: File: tmp.m Line: 5 Column: 1
> Function definitions are not permitted at the prompt or in scripts.
>
> also where i have importdata('filename') should this be importdata(files(k))
>
> knd regards
> Neetin Lad.

The message is self-explanatory - if you are using a custom function you'll need to have it as a separate file (in a directory that is in your MATLAB path). You can still use it in a script, but it has to be defined elsewhere (or else just put your function code into the main script and run it that way, without defining a function). Since you're sending a single input argument to your function, I believe you could use either currentFileName or files(k).name assuming you use the variable names I arbitrarily chose. If you are explicitly sending a file variable name as a string then you would have to use the single quotation marks.

Subject: read labview files in matlab.

From: Neet Lad

Date: 29 Nov, 2010 14:16:03

Message: 8 of 8

Thank you for all your posts i have resolved the matter of importing.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us