I have a text file that contains 4*10 array. I want to read 1st column element first and store that column in say x, process it and then read 2nd column and store in same variable x. Is there any commands for that? please help?
Show older comments
-1.9360 20.7501 -1.3800 0.2735 -1.9360 20.7501 -1.3800 0.2735 20.7501 -1.3800
-2.5797 27.6486 -1.3819 0.2524 -2.5797 27.6486 -1.3819 0.2524 27.6486 -1.3819
1.5073 28.2723 -0.0000 15.0002 1.5073 28.2723 -0.0000 15.0002 -0.0000 15.0002
-1.9770 37.0812 0.0000 15.0009 -1.9770 37.0812 0.0000 15.0009 0.0000 15.0009
3 Comments
KSSV
on 22 Sep 2016
As the text file is small..you can import data completely into a matrix and process it.
data = importdata('textfile.txt') ;
Sachin Patil
on 22 Sep 2016
KSSV
on 22 Sep 2016
you may try to save your text file as .xls file or .csv file then use the xlsread() function..
Accepted Answer
More Answers (1)
Stephen23
on 22 Sep 2016
This is a much simpler and more efficient code:
M = dlmread('test.txt');
for row = 1:size(M,1) % loop over the rows
M(row,:)
end
for col = 1:size(M,2) % loop over the columns
M(:,col)
end
Tested on this file:
1 Comment
Sachin Patil
on 22 Sep 2016
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!