Filter löschen
Filter löschen

Combine data from text files into 1?

3 Ansichten (letzte 30 Tage)
Tyler Lawson
Tyler Lawson am 4 Okt. 2022
Kommentiert: dpb am 5 Okt. 2022
I have equipment that gives us data at 3 frequency ranges. Each range (High, Mid, Low), has its own text file with 7 headers and 3 columns of data. How would I combine these 3 data sets so that they go from Lows to Highs and have no headers? I added the first handful of rows for each frequency as an example.
High:
Test Type: SE
Test Point Information: H HF
Fiber Gain dB External attenuation dB
! 50 0
Test Parameters - Start Frequency: Stop Frequency: RBW: Number of Points:
! 200000000 1000000000.00001 30 200
Frequency Amplitude SE
200000000 -95.7444746348 105.8548329235
201624084.182 -94.8430797684 105.586601757
203261356.611 -105.026149057 113.9170141066
204911924.381 -98.2910069978 110.6246375614
206575895.456 -104.618037004 114.6189605781
Mid:
Test Type: SE
Test Point Information: H MF
Fiber Gain dB External attenuation dB
! 50 0
Test Parameters - Start Frequency: Stop Frequency: RBW: Number of Points:
! 20000000 198852014.790596 30 394
Frequency Amplitude SE
20000000 -88.182304421 120.9731205046
20115461.26 -94.3640015779 127.6628331846
20231589.085 -95.81268609200001 129.5194587399
20348387.324 -98.3275216973 131.9908467909
Low:
Test Type: SE
Test Point Information: H LF
Fiber Gain dB External attenuation dB
! 50 0
Test Parameters - Start Frequency: Stop Frequency: RBW: Number of Points:
! 10000 19654172 30 200
Frequency Amplitude SE
10000 -73.7473367895 32.2434412276
10387 -77.5007700307 36.59746393959999
10790 -76.8728977036 36.36316745000001
11208 -76.2866404235 36.27402701850001
11642 -83.5528747158 43.83786599699999

Akzeptierte Antwort

dpb
dpb am 4 Okt. 2022
Exact details for the easiest way to handle the three files would depend on how they're named/saved so as to keep the sets associated together; somewhere you'll want to have an ID to identify who's who in the zoo, besides...
But, the details of that aside, with only three it's probably just as simple to simply write something such as
root='TheRootDataDirLocation';
dL=dir(fullfile(root,'*LOW*.txt')); % salt to suit wildcard to match naming convention
dM=dir(fullfile(root,'*MID*.txt'));
dH=dir(fullfile(root,'*HIGH*.txt'));
for i=1:numel(dl) % there must be same number Lo, Mid, High -- add error check first
tD=readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD=[tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD=[tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(root,'NEEDNAMINGCONVENTIONIDENTIFYEACHCASEHERE.'))
end
You could use readmatrix instead and skip all seven headerlines; the table form above may be handy to have the variable names for reference; your choice.
  13 Kommentare
Tyler Lawson
Tyler Lawson am 5 Okt. 2022
I figured it out! Using your help and your code I was able to make it run through the different test types and create a single file for each of them and graph it. It asks for some input in order to name the files correctly but it works!
THANK YOU SO MUCH!
I do have one last question for you though! I have a plot being made and it brings up a dialog box in order to save it where the user wants. However, the plot still opens. Is there a way to surpress the plot so it doesn't open everytime the code is run and just saves them instead?
dpb
dpb am 5 Okt. 2022
Wherever you create the figure (or, if you're letting the figure be created automagically, then do the creation yourself first instead) write
hF=figure('Visible','off');
then carry on as before.
If you want to have a way for the user to inspect one, then
hF.Visible='on';
will show the figure...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by