Read Data

1 view (last 30 days)
David Lopez
David Lopez on 14 May 2012
I need to read a file .txt with this format...
1945; 6937;N;000 1946; 6976;N;000 1947; 6987;N;000
how i can read these data i dont know a lot about the sintaxis, pls help and i want plot the year 1945 and the level 6937 Perform linear regression and plot the trend data.
and finally Calculate the slope of the trend.
  5 Comments
David Lopez
David Lopez on 14 May 2012
of course for a lot of years
1945 6937
1946 6976
1947 6987
...
2011 7133
per isakson
per isakson on 14 May 2012
But what does the file look like? What happened to "N;000"?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 May 2012
Try
fid = fopen('YourFile.txt', 'rt');
C = textscan(fid, '%f;%f;%*c;%*f', 'CollectOutput', 1);
fclose(fid);
Y = C{1}(1:2:end);
L = C{1}(2:2:end);
plot(Y, L)
  3 Comments
Walter Roberson
Walter Roberson on 15 May 2012
Hmmmm, maybe the CollectOutput would not be appropriate here, and instead
Y = C{1}; L = C{2};
Better test to be sure.
David Lopez
David Lopez on 15 May 2012
actually, i did this
[ax]=C{1};
ay=ax(:,1);
al=ax(:,2);

Sign in to comment.

More Answers (0)

Categories

Find more on Linear and Nonlinear Regression 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!