How to read numeric data from text file and plot graph for given numeric data?

3 ビュー (過去 30 日間)
Dear Users,
I have a text file like this:
.
VERSION 1.0 1
.HIERARCHY CHARACTER
.COORD X Y T
.SEGMENT CHARACTER
.X_POINTS_PER_INCH 2500
.Y_POINTS_PER_INCH 2500
.POINTS_PER_SECOND 120
.PEN_DOWN
3750 555 10266
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3750 555 0
3760 557 0
3760 557 0
3777 556 0
3788 551 0
3799 549 0
3817 541 0
3833 532 0
3851 516 0
3868 501 0
3883 480 0
3895 456 0
3906 431 0
3913 402 0
3915 376 0
3913 348 0
3905 324 0
3894 304 0
3878 289 0
3853 280 0
3825 278 0
3793 287 0
3759 300 0
3720 324 0
3680 355 0
3640 399 0
3597 446 0
3560 504 0
3524 570 0
3493 643 0
3468 720 0
3447 801 0
3434 884 0
3432 967 0
3441 1046 0
3458 1123 0
3486 1194 0
3523 1255 0
3572 1304 0
3629 1344 0
3692 1370 0
3761 1386 0
3831 1387 0
3899 1374 0
3963 1348 0
4021 1311 0
4068 1266 0
4107 1208 0
4134 1144 0
4151 1077 0
4159 1010 0
4160 946 0
4156 887 0
4146 838 0
4136 796 0
4119 768 0
4103 752 0
4083 746 0
4061 752 0
4038 766 0
4009 789 0
3982 819 0
3954 855 0
3925 897 0
3900 944 0
3876 992 0
3857 1040 0
3838 1086 0
3820 1129 0
3808 1165 0
3794 1198 0
3778 1225 0
3764 1246 0
3745 1258 0
3724 1264 0
3697 1264 0
3667 1261 0
3634 1251 0
3597 1238 0
3563 1216 0
3532 1195 0
3496 1178 0
3468 1153 0
3442 1131 10859
.PEN_UP
I want to read numeric data in the above three coloumns like x,y,z & I want to plot graph for
x vs y
  1 件のコメント
Walter Roberson
Walter Roberson 2014 年 3 月 27 日
Is the .PEN_DOWN always at the exact same line, line 25 of the file?
The number of lines before the .PEN_UP I am going to guess to be variable.
Can there be multiple DOWN and UP events in the same file?

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 27 日
fid=fopen('file.txt')
s=textscan(fid,'%d %d %d','headerlines',23)
fclose(fid)
x=s{1}
y=s{2}
z=s{3}
  5 件のコメント
Alex M.
Alex M. 2016 年 11 月 29 日
Hi, I am using this code to plot y vs x from a .txt file. However, my range of x data are from 200 to 1000 and I only want to plot from 400 to 700 for the x axis and have their associate y values. How can I implement this in my code plotting in 2D (my txt file is only 2 columns)?
Walter Roberson
Walter Roberson 2016 年 11 月 29 日
xlim([400 700])

サインインしてコメントする。

その他の回答 (1 件)

Cagas Akalin
Cagas Akalin 2016 年 10 月 13 日
Dear All,
The problem that I am dealing with is very simillar to this you' ve discussed before here. The only difference that I have in my case is the number of data lines in my "ThermocoupleCombined.txt" file which is exactly 5615917.
The shorthaned content of the data file that I am dealing with looks like as follows.
channel names:
09/07/2016 06:20:09 PM - Thermocouple - SC1Mod2_ai2
start times:
9/7/2016 18:20:13.504689
dt:
0.010000
data:
8.857533E+1
8.857165E+1
8.856430E+1
8.857165E+1
8.856798E+1
8.857165E+1
8.856798E+1
8.857900E+1
8.856430E+1
8.857165E+1
8.857165E+1
8.856798E+1
8.856430E+1
8.856798E+1
.
.
.
2.635587E+1
2.635209E+1
2.635965E+1
2.635587E+1
2.635209E+1
2.635965E+1
2.635965E+1
2.635209E+1
2.635587E+1
2.635965E+1
2.634832E+1
and the code I use is
clear all
close all
clc
fileID = fopen('ThermocoupleCombined.txt','r');
Crude_Data = textscan(fileID,'%f','HeaderLines','2');
fclose(fileID);
C = transpose(0:0.01:0.01*(length(Crude_Data{1})-1));
plot(C,Crude_Data{1})
The code above draws the data up to 76757 and the rest is not included inside "Crude_Data" and not plotted.
Can you please give me your suggestions regarding the problem I have?
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 11 月 29 日
You would need HeaderLines 7 for that file.
If you made that change and the data only read as far as line 76757 then chances are that there is a problem in the file close to that line. We would need to see a few lines before and after the problem line to tell. One test would be to delete a few lines at the beginning of the input and see if the problem moves the same amount (if so then the content is likely the problem) or if the problem stays at the same relative location (of so then something odd is happening with memory filling or something like that.)
Farnaz Mohammadi
Farnaz Mohammadi 2017 年 11 月 3 日
Hi, I have a question, but I don't know where should I put it, If you know any way, I really appreciate if you help me, My problem: I have a text file (actually it is tca.network but contains text) that is the output of a package written in java named JMassBalance, it is used to produce randomized graphs of metabolic network I need to use this output as an input of another software, but the format doesn't match... I have put my file here, and one file which it should become so that I can use it as a desired input.. Could you help me how can I transform this?
Thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by