MATLAB Answers

0

How can i read second column from a txt file in matlab

Asked by arooba mazhar on 12 Mar 2017
Latest activity Edited by Walter Roberson
on 12 Mar 2017

  0 Comments

Sign in to comment.

1 Answer

Answer by Abdurrehman on 12 Mar 2017
Edited by Abdurrehman on 12 Mar 2017
 Accepted Answer

[Filename,FilePath]=uigetfile('\\Address\*.txt','Load File');
FileName=fullfile(FilePath,Filename);
NoofCol=7;% Total no of col. in ur file
Format=repmat('%s',1,NoofCol);
fid=fopen(FileName,'rt');
Header=fgetl(fid);% to delete first line (You can use this line as title for data plotting)
data_cell=textscan(fid,Format,'HeaderLines',1,'CollectOutput',1);
fclose(fid);
data=data_cell{1};
SecCol=str2double(data(:,2));
Hope the above will help you

  3 Comments

I have edited my code, it works fine with your given file
Thanks alot it worked :)
It was my very first answer :-)

Sign in to comment.