How do I convert many files .spt type to .dat type in matlab? need urgent help!

Is fluorescence data in which the first column is the wavelength and the second column is the intensity.

5 Comments

Bethânia - why do you want to convert the file from an spt to a dat? Is the former just a text file with numeric data in two columns? If so, are you trying to consolidate all data from those multiple files into one other file? What do you expect/need the format of the dat file to be - text or binary, one for each spt file, or..?
Hello Geoff, I want each .spt file to be converted into .dat file so I can use the numeric data (wavelength and intensity) in a spreadsheet on Origin Program and thus perform a PCA.
Thank you for feedback. Was enlightening?
=/
Bethânia - but what is the format of the spt file? I guess it isn't a text file else you would use it (as is) in your spreadsheet...
So, the format is SPOT file according to what I observed in MatLAb Help. I can only use the data in the spreadsheet if in dat format. And yes, .SPT FILE isn't a text file (contains only some descriptive passage created automatically by software).
Understand? And again, very grateful.
Could you help me by writing in the space for the answer? This way, I get an email as soon as you post a reply in this particular space.

Sign in to comment.

 Accepted Answer

If you say it is a SPOT file then could http://www.mathworks.com/help/bioinfo/ref/sptread.html sptread(). I am not familiar with SPOT files so i'm not sure how it will be imported.

2 Comments

Strange how little documentation there appears for this function (from the Bioinformatics Toolbox). According to the link that Joseph provided, upon using the above on a spt file, the data structure returned has the following fields
Header
Data
Blocks
Columns
Rows
IDs
ColumnNames
Indices
Shape
If there are just two columns, then perhaps, Bethânia, you can do something like the following
% create example folder and file name variables
sptFolder = '/Users/bethânia/mySptFolder';
sptFile = 'myFile1.spt';
% combine the folder and file name
sptFileToRead = fullfile(sptFolder,sptFile);
% read the SPT file
sptData = sptread(sptFileToRead);
% get the column data (we assume that this is a mx2 matrix)
colData = sptData.Columns
% copy the column data to a "dat" file which will just be a
% text file
[sptFolder,sptFilename,sptExtension]=fileparts(sptFileToRead);
datFilename = [sptFilename '.dat'];
datFileToWrite = fullfile(sptFolder,datFilename);
% write the column data to file
dlmwrite(datFileToWrite,colData);
The above is guesswork only given the structure (I don't have the toolbox to test this out); the assumption is that you can access the luminosity and intensity from the Columns structure, and that it is in fact an mx2 matrix. If true, then the above should work.
Since there are multiple files, then you could get all of the files (again assuming that all are in the same directory/folder) as
sptFolder = '/Users/bethânia/mySptFolder';
allSptFiles = dir(fullfile(sptFolder,'*.spt'));
for k=1:length(allSptFiles)
sptFile = allSptFiles(k).name;
sptFileToRead = fullfile(sptFolder,sptFile);
% etc.
end
Try the above, and pay careful attention to the sptData structure and its Columns data
Thanks a lot! I'll try now and these days. Post here what I get!
=)

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!