|
Alessandra <danda.galli@gmail.com> wrote in message <1075412655.5267.1278766191278.JavaMail.root@gallium.mathforum.org>...
> Hi There,
>
> I cannot menage to convert an array cell into double.
> I'll expain you better. I imported a txt file of two coloums, the first is the problematic one, it looks like this:
>
> S 75
> S100
> S 50
> S 1
> S128
> etc..
>
> Some elements have a space, some two spaces some none.
> While importing I used textread and this syntax that allowed me to split the "numeric" part of these elements from the "Character" part.
> My two coloumns are stim and time:
>
> [trash, stim, time] = textread(files, '%c %s %f', 'delimiter','\t', 'whitespace', '', 'headerlines',2);
> clear trash
>
> This works out fine but one I have my stim array this is saved as cell and if I print it, it looks like this:
>
> '128 '
> ' 1'
> ' 50'
> etc..
>
> I need to convert this new array of only numbers although treated as cell into a double so that I can creat a matrix with stim and time as coloumn. I need this since the stim variable has markers that I need to filter the time variable.
>
> I hope it was clear, I can't find a solution for this, could you help me?
>
> Thanks a lot
>
> Ale
one of the many solutions
- given the anatomy of your file...
fnam='foo.txt'; % <- your file name...
s=textread(fnam,'%s','delimiter','\n');
s=regexp(s,'\d+','match');
r=cellfun(@(x) sscanf(x,'%g'),[s{:}],'uni',false)
% r = [75] [100] [50] [1] [128]
us
|