Page 1 of 1
dlm read error
Posted: Thu Jun 07, 2018 6:34 am
by samberia
i am trying to read actuation_power.sto file in matlab using command
x = dlmread('CMCResults\3_ik\3_Actuation_power.sto', '\t', 24,0);
but its giving me error
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1621, field number 33) ==> #QNAN000
-0.08174060 -0.00417017 -0.01498641 -0.00461682 -0.00923849
0.00108106 0.00036024 -0.00624527 -0.01703937 0.00229797
0.00460482 ...
i have also used command uiimport but it is not able to read the file completly
Re: dlm read error
Posted: Mon Jun 11, 2018 2:16 am
by mitkof6
Please use the following function to load .sto files:
Code: Select all
function q = readMotionFile(fname)
% Purpose: This function reads a file in the format of a SIMM motion file
% and returns a data structure
%
% Input: fname is the name of the ascii datafile to be read
% ('character array')
%
% Output: q returns a structure with the following format:
% q.labels = array of column labels
% q.data = matrix of data
% q.nr = number of matrix rows
% q.nc = number of matrix columns
%
% ASA 12/03
% Modified by Eran Guendelman 09/06
% Open ascii data file for reading.
fid = fopen(fname, 'r');
if fid == -1
error(['unable to open ', fname])
end
% Process the file header;
% store # data rows, # data columns.
q.nr = 0; % Added to ensure that the q structures from reading a motion file
q.nc = 0; % are always the same, even if nr and nc are different orders in file.
nextline = fgetl(fid);
header = {nextline};
while ~strncmpi(nextline, 'endheader', length('endheader'))
if strncmpi(nextline, 'datacolumns', length('datacolumns'))
q.nc = str2num(nextline(findstr(nextline, ' ')+1 : length(nextline)));
elseif strncmpi(nextline, 'datarows', length('datarows'))
q.nr = str2num(nextline(findstr(nextline, ' ')+1 : length(nextline)));
elseif strncmpi(nextline, 'nColumns', length('nColumns'))
q.nc = str2num(nextline(findstr(nextline, '=')+1 : length(nextline)));
elseif strncmpi(nextline, 'nRows', length('nRows'))
q.nr = str2num(nextline(findstr(nextline, '=')+1 : length(nextline)));
end
nextline = fgetl(fid);
header{end + 1} = nextline;
end
q.header = header;
% Process the column labels.
nextline = fgetl(fid);
if (all(isspace(nextline))) % Blank line, so the next one must be the one containing the column labels
nextline = fgetl(fid);
end
q.labels = cell(1, q.nc);
for j = 1:q.nc
[q.labels{j}, nextline] = strtok(nextline);
end
% Process the data.
% Note: transpose is needed since fscanf fills columns before rows.
q.data = fscanf(fid, '%f', [q.nc, q.nr])';
fclose(fid);
return;