Clear Filters
Clear Filters

Why does the importdata function read in my file data incorrectly when reading data from a .mp file

4 views (last 30 days)
When I run the function MyData = importdata(filename); I am getting an issue with how the data is reading in.
In the created MyData variable I should now have 2 new fields textdata and data which should be defined by the ' ' delimiter and their values/text.
Below is a breakdown of my code + data and the outputs I'm getting if anyone can help or has had this type of issue before?
Here's an example of what the data from the .mp file looks like as a text file
$Female = 0
$Adult = 1
$Height = 1885
$BodyMass = 71.8
$SamplingRate = 250
Instead of breaking the data up into the appropriate sections based on the ' ' delimiter it does this for textdata
'$Female ='
'$Adult = 1'
'$Height = 1'
'$BodyMass ='
And this for data
0
NaN
885
71.8000000000000

Accepted Answer

Walter Roberson
Walter Roberson on 23 Nov 2016
fid = fopen(filename, 'rt');
datacell = textscan( fid, '%s=%f' );
fclose(fid)
textdata = datacell{1};
data = datacell{2};

More Answers (0)

Community Treasure Hunt

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

Start Hunting!