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

Walter Roberson
Walter Roberson 2012년 5월 14일
Are those all on one line, or are those three separate lines in the file?
Do you only want to plot for 1945? And only for 6937? If so then what is the variable that you want to plot?
per isakson
per isakson 2012년 5월 14일
Does it look like this in an editor? Does ";" stand for new_line in the in text file?
David Lopez
David Lopez 2012년 5월 14일
yes the file is 1 (one) line, i have to separate the data and remove N;000, i just need take the year and the level and plot
David Lopez
David Lopez 2012년 5월 14일
of course for a lot of years
1945 6937
1946 6976
1947 6987
...
2011 7133
per isakson
per isakson 2012년 5월 14일
But what does the file look like? What happened to "N;000"?

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 14일

0 개 추천

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

David Lopez
David Lopez 2012년 5월 14일
thank you so much
Walter Roberson
Walter Roberson 2012년 5월 15일
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 2012년 5월 15일
actually, i did this
[ax]=C{1};
ay=ax(:,1);
al=ax(:,2);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by