Problems importing files using importdata
1 view (last 30 days)
Show older comments
[EDIT: 20110718 13:49 CDT - reformat - WDR]
I have a text file that I am importing using the importdata function that is apparently too long to be imported completely. Only the first 2952 lines are being brought into MatLab. The purpose of importing the file is to extract the start time, mass, and intensity of varying peaks from the mass spectrometer.
This is the code I'm using:
filename = 'Coumarin 47 50ppm 3.txt';
D = importdata(filename);
C = char(D);
I need it to be in a char array in order for my program to run correctly. D comes in as a cell array with one line from the txt file in each row in the first column.
Any help with this would be appreciated. Thanks!
This is a sample of the formatting of the .txt file I'm importing:
ScanHeader # 8
position = 8, start_mass= 150.000000, end_mass = 1000.000000
start_time = 0.113000, end_time = 0.000000, packet_type = 0
num_readings = 20, integ_intens = 357904.000000, data packet pos = 0
uScanCount = 0, PeakIntensity = 41486.000000, PeakMass = 284.697388
Scan Segment = ffff, Scan Event = ffff
Precursor Mass
Collision Energy
Isolation width
Polarity positive, Cenrtoid Data, Full Scan Type, MS Scan
SourceFragmentation Any, Type Ramp, Values = 0, Mass Ranges = 0
Turbo Scan Off, IonizationMode Nanospray, Corona Any
Detector Any, Value = 0.00, ScanTypeIndex = -1
DataPeaks
Packet # 0, intensity = 5912.000000, mass/position = 167.135193
saturated = 0, fragmented = 0, merged = 0
Packet # 1, intensity = 8019.000000, mass/position = 189.277893
saturated = 0, fragmented = 0, merged = 0
Packet # 2, intensity = 11636.000000, mass/position = 201.145355
saturated = 0, fragmented = 0, merged = 0
Packet # 3, intensity = 3690.000000, mass/position = 204.261841
saturated = 0, fragmented = 0, merged = 0
Packet # 4, intensity = 14393.000000, mass/position = 205.380890
saturated = 0, fragmented = 0, merged = 0
0 Comments
Answers (3)
Sean de Wolski
on 18 Jul 2011
perhaps convert each cell to a char and then run over it with a loop or cellfun in your function?
Cchar = cellfun(@char,C,'uni',false);
In order to make the whole thing a char and not a cell, you'll have to add something to the end of every value shorter than the longest one because it must be a rectangular matrix.
0 Comments
Walter Roberson
on 18 Jul 2011
The file probably isn't too long: the 2953'rd line probably has a different format. Check, for example, for a leading space or tab on that line -- a leading tab was (I seem to recall) the difficulty the last time someone had a similar file length problem.
0 Comments
Walter Roberson
on 18 Jul 2011
fid = fopen(filename, 'rt');
D = textscan('Packet #\d, intensity = %f, mass/position = %f saturated = %d, fragmented = %d, merged = %d', 'CollectOutput',true);
fclose(fid);
PN = D{1};
Intensities = D{2}(:,1);
MassPos = D{2}(:,2);
flags = D{3};
0 Comments
See Also
Categories
Find more on Historical Contests in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!