Dataline [n1 n2] didn't work

2 views (last 30 days)
rimbak
rimbak on 15 Mar 2022
Answered: Walter Roberson on 17 Mar 2022
Hello,
i have a csv of 18 000 line I need to import this data from 300 to 17000, i have tried data.dataline = [300 17000] but it returns me an error that Dataline must be a positive intreger , i don't know where this error come from
thanks in advance for your answers
Best regards
  5 Comments
rimbak
rimbak on 16 Mar 2022
thanks for your answers
Adam Danz
Adam Danz on 16 Mar 2022
@rimbak it would be helpful to know/have the following
  1. The entire copy-pasted error message.
  2. The version of Matlab you're using
  3. A smaller version of your file that we could run to try to reproduce the error. I'm surprised that a file with 18k lines and with only 1 column of numeric data is very large. Nevertheless, having a representitive sample of the document (ie, lines 300-400) might be helpful.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 17 Mar 2022
Unfortunately in your release, DataLines only permitted a single value, not a range of values.
PerLine = 343;
DataLines = [300 17960]
[filename, filepath] = uigetfile();
if ~ischar(filename); return; end %user cancel
fullname = fullfile(filepath, filename);
fmt = repmat('%f', 1, PerLine);
headerlines = DataLines(1)-1;
numlines = DataLines(2)-DataLines(1)+1;
[fid, msg] = fopen(fullname, 'rt');
if fid < 0;
error('Could not open file because "%s"', msg);
end
data = cell2mat( textscan(fid, fmt, numlines, 'Headerlines', headerlines, 'Delimiter', ';') );
fclose(fid);
You will need to figure out which column is force and which is acceleration.
Note: if you only need selected columns, then the reading can be made more efficient by manipulating the computed fmt

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!