MATLAB Answers

0

How to import large text file data in to workspace?

Asked by Abdurrehman on 4 Feb 2017
Latest activity Commented on by Muhammad Abdurrehman on 4 Feb 2017
Hi, I am having a text file with following format
First Line is a string contains device parameters
rest is 18000x12 Lines format is double
I am using uigetfile to access my file then fscanf to read data. But this text file should reside in the same workscpace where the reading script is placed.
Is there any way to read above file without placing .txt file into current directory. The command importdata is not useful in my case only.

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 4 Feb 2017
 Accepted Answer

[filename, pathname] = uigetfile(.....)
fullname = fullfile(pathname, filename);
ncol = 12;
fmt = repmat('%f', 1, ncol);
fid = fopen(fullname, 'rt');
data_cell = textscan(fid, fmt, 'HeaderLines, 1, 'CollectOutput', 1);
fclose(fid);
data = data_cell{1};

  1 Comment

Working perfectly ! Dear thanks a lot for such a quick reply.

Sign in to comment.