Help split a text file into 3 arrays (textscan)

2 次查看(过去 30 天)
Greatings, I am fairly new with importing text files and extracting what I need so any suggestions would be great. I have a text file as:
1 02/06/2012 10:55:43.109 23.580898 2 02/06/2012 10:55:43.109 23.431202 3 02/06/2012 10:55:43.109 23.081917 1 02/06/2012 10:55:43.750 23.580898 2 02/06/2012 10:55:43.750 23.431202 3 02/06/2012 10:55:43.750 23.081917
I am wondering if its possible to split this into:
1 02/06/2012 10:55:43.109 23.580898 1 02/06/2012 10:55:43.750 23.580898
Separating each group by the 1st column. I was thinking of implementing a while loop that would look like:
%Read First Line [a b]=strtok(fid) % Implement Logic command while a = 1 % Store in some cell Any suggestions would be great..

回答(3 个)

RNTL
RNTL 2012-2-10
can you explain what is it exactly to you want to transform ? I couldn't understand it from the example you gave.

Lucas
Lucas 2012-2-10
Ah I see the problem the text file showed up wrong
1 02/06/2012 10:55:43.109 23.580898
2 02/06/2012 10:55:43.109 23.431202
3 02/06/2012 10:55:43.109 23.081917
1 02/06/2012 10:55:43.750 23.580898
2 02/06/2012 10:55:43.750 23.431202
3 02/06/2012 10:55:43.750 23.081917
This is what the text file looks like, with the exceptions of no spaces between the text. But I have figured out a way to read the text using a for loop (converting the 1,2,3 to a real number ) and stating
if a == 1
Do this
elseif a ==2
Do this ...etc

RNTL
RNTL 2012-2-10
if all you wish is every 3rd row, why not simply using indexing on what you have ?.. say Data is the name of the array you're describing above.
so co1_1 = data(1:3:end,:); col_2 = data(2:3:end,:); .. and so on

Community Treasure Hunt

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

Start Hunting!

Translated by