Import labview ascii text file as cell array

2 views (last 30 days)
I have these labview .lvm files which I want to rearrange using MATLAB code. I think I can handle the rearranging bit, but I have not found a way to import the file which contains both numbers and strings into a cell array.
The file is of the format:
  • 'tab' 'double' 'space' 'double' 'tab' 'many characters/numbers which I would import as single string'
  • 'tab' 'double' 'space' 'double'
  • 'tab' 'double' 'space' 'double'
  • 'tab' 'double' 'space' 'double' 'tab' 'many characters/numbers which I would import as single string'
  • 'tab' 'double' 'space' 'double'
  • 'tab' 'double' 'space' 'double'
  • etc
fopen returns -1 with any read/write argument, dlmread produces "Mismatch between file and format string.", importdata works but separates the data into a matrix and a cell so I can't pick out the individual parts, and lvm_import available on the codeshare produces the error "This does not appear to be a text-format LVM file (no header)."
Any ideas on how to get this file into MATLAB? Thanks.

Accepted Answer

dpb
dpb on 11 Jul 2014
content = textread('filename','%s','delimiter','\n','whitespace','');
Will leave a cell array for each line.
You'll have to split the various line formats between the header lines if "rearranging" means reordering values other than by line.
You should also be able to use textscan in a loop and read the sections altho if there are different numbers of lines between sections and can't parse that value from the header line it's more-or-less parsing line-by-line.
And, of course, there is always just using fgetl and processing the file on that basis if the rearrangement is with a line--you don't give any clues in that regard.
The comment of ...fopen returns -1 with any read/write argument, ... indicates that fopen call is wrong--either the file doesn't exist in the working directory or on matlabpath or the like. Use the alternate optional returns to find out further info on what the failure is.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!