Azzera filtri
Azzera filtri

Combining text files

1 visualizzazione (ultimi 30 giorni)
Melissa Patterson
Melissa Patterson il 16 Giu 2011
[EDIT: 20110616 11:05 CDT - reformat - WDR]
[EDIT: 20110616 10:25 CDT - merge from duplicate question - WDR]
[EDIT: 20110616 09:43 CDT - remove confidential material, reformat - WDR]
My company uses MATLAB for everything. I have MATLAB generated files that I want to combine. An simplified example of the files is below:
File1.txt:
Pressure: 20 psi
FY: 1,2,3
FX: a,b
File2.txt:
Pressure: 25 psi
FY: 4,5,6
FX: c,d
File3.txt:
Pressure: 30 psi
FY: 7,8,9
FX: e,f
I want to combine the files so that the output looks something like this:
Minimum Pressure: 20 psi
Maximum Pressure: 30 psi
FY: 1,2,3,4,5,6,7,8,9
FX: a,b,c,d,e,f
I have so little experience programming, that I do not even know how to read in the files. Please take pity on my and tell me how to start. Start? Heck! I need all the help I can get! Tell me everything you think will be helpful.
Thank you!
Here is what I have so far, and I know, I have failed miserably:
[Program removed as it contained company-confidential material - WDR]
[Material from duplicate question]
I have multiple MATLAB created text files that I need to combine. A simplified sample file looks like this:
File_1_D100.txt:
Pressure: 20 psi
D Number: D100
FX: a,b,c
FY: 1,2,3,4
File_2_D100.txt:
Pressure: 30 psi
D Number: D100
FX: d,e,f
FY: 5,6,7,8
I would like the output to look like:
Min Pressure: 20 psi
Max Pressure: 30 psi
D Number: D100
FX: a,b,c,d,e,f
FY: 1,2,3,4,5,6,7,8
1.)I don't know how to read in multiple files, 2.)I don't know how to combine blocks of data, 3.)and I don't know how to make the final file recognize the max and min pressures. This is what I have so far:
function Mult_Pressures_Tire_File_Reader
%
%
% Program Development Date : June 15, 2011
%
% Program Developed By : Melissa Patterson
%
% Units of output and internal parameters
%
%******************************************************************%
% The first step in the process is to read in the SES tire files and sort
% data by coefficient type.
%
%
%
clear all;
close all;
warning off;
% Load the appropriate text files
[fname,pname]=uigetfile('*.tir','Please select all pressures');
full_fname=[pname, fname];
load(full_name)
fname=fname(1:size(fname,2)-4);
answer= questdlg('Please enter D number:');
% Open and Write Output File
id = fopen(output_filename, 'wt');
fprintf(id, '!\n');
fprintf(id, '! Date Created : June 14, 2011\n');
fprintf(id, '! Created By : Melissa Patterson\n');
fprintf(id, '!\n');
fprintf(id, '[Tire Model Specifications]\n');
fprintf(id, 'Tire_Model_Version : 6.5\n');
fprintf(id, 'Tire_File_Version : 3.45\n');
fprintf(id, ' Length_Units : ''mm''\n');
fprintf(id, ' Force_Units : ''newton''\n');
fprintf(id, ' Angle_Units : ''degrees''\n');
fprintf(id, ' Mass_Units : ''kg''\n');
fprintf(id, ' Time_units : ''second''\n');
fprintf(id, '!\n');
fprintf(id, '[Tire Details]\n');
fprintf(id, 'Tire_Construction : %6.4f'\n',D_Number);
fprintf(id, 'Tire_Manufacturer : Goodyear\n');
fprintf(id, 'Tire_Year : 2011\n');
fprintf(id, 'Tire_Application : Road Course\n');
fprintf(id, 'Tire_Position : All !All, LF, RF, LR, RR, LS, RS\n');
fprintf(id, 'Tire_Series : Sprint_Cup ! Sprint Cup, Nationwide, Truck\n');
fprintf(id, '!\n');
fprintf(id, '[Testing Details]\n');
fprintf(id, 'Minimum_Pressure : %6.4f ! psi\n');
fprintf(id, 'Maximum_Pressure : %6.4f ! psi\n');
fprintf(id, 'Pressure Increments : %6.4f ! psi\n');
fprintf(id, 'LONGVL = %7.4f $Measurement speed\n',(str2num(Test_Speed))*0.44704);
fprintf(id, 'TYRESIDE = ''RIGHT'' $Mounted side of tyre at vehicle/test bench\n');
fprintf(id, '$--------------dimensions\n');
fprintf(id, '[DIMENSION]\n');
fprintf(id, 'UNLOADED_RADIUS = %6.4f $Free tire radius\n',ULR);
fprintf(id, 'WIDTH = %6.4f $Nominal section width of the tyre\n',(str2num(Nom_Section_Width))/1000);
fprintf(id, 'ASPECT_RATIO = %6.4f $Nominal aspect ratio\n',Nom_Aspect_Ratio);
fprintf(id, 'RIM_RADIUS = %6.4f $Nominal rim radius\n',(str2num(Rim_Radius))*(25.4/2000));
fprintf(id, 'RIM_WIDTH = %6.4f $Rim width\n',(str2num(Rim_Width))*25.4/1000);
fprintf(id,
fclose all;
  2 Commenti
Andrew Newell
Andrew Newell il 16 Giu 2011
Could you please provide a more meaningful title for your question? See http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer. Also, some of the code needs formatting so we can read it easily - see http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question.
Walter Roberson
Walter Roberson il 16 Giu 2011
Somewhere along the line part of the program went missing -- the final fprintf() is an incomplete statement.

Accedi per commentare.

Risposte (1)

Baalzamon
Baalzamon il 7 Lug 2011
How many files do you have? Are they all named and structured the same way?
First step:
Help >> Product help >> By category >> Data Import and Export

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by