MATLAB: How to convert executable file or its contents to text file

.exe .txt extraction

An instrument I work with produces *.picotd files that are specialized text files, but appear as executable when I export to my Mac. I am trying to get the data (2-d) from the executable .picotd file (after the header) so that I can make plots, do analyses, etc.
I can't find any resources on this extraction or conversion. Someone provided me a function that should supposedly extract the data, but it messes up the data as one whole column becomes zeroes. I don't mind avoiding this function if I can find a cleaner way of getting the data. I am not extremely experienced with matlab but can work through examples and such.
This is the function ("loadpico") that should ideally extract the data:
fid=fopen(name); % Load file
fos=fopen('temp.tmp','w');
tline = fgetl(fid);
tline = fgetl(fid);
tline = fgetl(fid);
tline = fgetl(fid);
tline = fgetl(fid);
while(not(feof(fid)))
tline = fgetl(fid);
fprintf(fos,'%s\n',tline);
end
fclose(fos);
fclose(fid);
The software outputs hundreds of waveforms, each one being a .picotd file. I'm trying to load them all at once, so I can stack them and plot them to create 2-D and 3-D plots. The following is my initial attempt to do a single folder of waveforms:
addpath(genpath('filepath/folder));
fnames=dir('*picotd');
numfids = length(fnames)
vals = cell(1, numfids);
for k = 1:numfids
vals{k} = loadpico(fnames(k).name);
end
I think this script had its own issues as when I plotted vals{1}, vals{2} etc, instead of a single line in each plot, there were two lines (one for the x-column, one for the y-column, which became all zeroes as I had mentioned before).
Any help is much appreciated.

Best Answer

OK, with the additional information provided there's now enough to move comments to an answer...with some background discussion as preamble for context--
MAJOR EDIT With the final resolution of the question of what the function is that wasn't shown in its entirety, I've removed all that now superfluous discussion after noting that hopefully for future you'll be far more careful in ensuring to post enough information to provide the necessary inputs.
In this case, reverting back to the original question of how to process the files, your start is pretty-much ok with the exception of I'd recommend against using cell arrays in favor of doubles and throw away the very crude import function in favor of just reading the files directly...
Oh, one issue...are the waveforms the same length for each? That'll complicate things if not, I'll make the assumption here they are...
d=dir('*picotd');
N = length(d);
[t,w]=textread(d(1).name,'%f%f','headerlines',6); % read first for size
T=zeros(length(t),N); W=T; % preallocate space for time,waveform vectors
T(:,1)=t;
W(:,1)=w; % save the first in the larger array
for k = 2:N % now do rest...
[T(:,k),W(:,k)]=textread(d(1).name,'%f%f','headerlines',6);
end
At the end you'll have a 2D array of the time delay and voltages by column for each file in the subdirectory. This can be plotted for comparative purposes simply by
plot(T,W)
It does, as noted up front, require that the waveforms are all the same length in order to put into a "regular" double array; if that isn't the case then either you'll have to augment shorter to longest length or trim longer to shortest or revert to the cell array.
The extension on the file is immaterial other than for any associations that may be built into the OS or that are user set. I don't know Mac but .picotd is a unique extension but shouldn't have any bearing at all on reading the file.
END UPDATE Rest still had some useful info, methinks... --dpb
Moving on to the data file description, that's an essentially trivial file format to read, there are six (6) header lines including the blank <spare> one and then two columns of tab-delimited data. All that takes to read is
fid=fopen('filename.picotd','r'); % open a given file
waveform=cell2mat(textscan(fid,'%f%f','collectoutput',1,'headerlines',6));
and you'll have the time vector in variable waveform(:,1) and the associated voltages in waveform(:,2).
To read multiple files, simply encapsulate the above in a loop as you indicated before over the files returned from dir with an appropriate wildcard for the files wanted (or simply '*' if all in a given subdirectory). There should be no need whatever to rename any file at all, although that could certainly be done with a global OS renaming command if wanted, but it's an exercise that isn't needed.
Oh, as a footnote, don't forget to fclose(fid) the file when you've done the read to not keep around a "veritable plethora" of unneeded file handles/open files.
UPDATE
Replace your loadpico function with the following...
function f=loadpico(filename)
% Read picometrix file

% W=loadpico(FILENAME) reads a Picomatrix file into a two-column
% double-precision array of time, voltage.
f=textread(nom,'','headerlines',6);
end
or, perhaps as noted, the following variation instead might has some advantages--
function [t,v]=loadpico(filename)
% Read picometrix file
% [t,v]=loadpico(FILENAME) reads a Picomatrix file returning the
% time, voltage column vectors from the file FILENAME.
[t,v]=textread(nom,'%f%f','headerlines',6);
end
Of course, at this point, it's almost as simple to just use the i/o statement by itself foregoing the intermediary function overhead entirely.