From: us on
Alessandra <danda.galli(a)gmail.com> wrote in message <1075412655.5267.1278766191278.JavaMail.root(a)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
From: Alessandra on
Hi dpb,

I tried your method, it works indeed but only on the elements I input in v, namely:

s={'128 ';' 1 ';' 50 '; ' 75 '};
v=zeros(size(s));
for idx=1:length(s), v(idx)=str2num(s{idx});
end

I need that the sequence of the stimuli is respected as it appears on my file. There are more than 1000 data point in my coloumn, I would need to input the whole coloumn if you know what I mean.

My array is stim and I tried to do soemthing like s={stim};
but it prints this:
{1403x1 cell}
and if I run your script I get this error:

>> s={stim};
>> v=zeros(size(s));
for idx=1:length(s), v(idx)=str2num(s{idx});end
??? Error using ==> str2num at 33
Requires string or character array input.

This is a very annoying problem..
Thanks a lot guys for helping me!

Alessandra
From: us on
Alessandra <danda.galli(a)gmail.com> wrote in message <1217621656.7454.1278793617867.JavaMail.root(a)gallium.mathforum.org>...
> Hi dpb,
>
> I tried your method, it works indeed but only on the elements I input in v, namely:
>
> s={'128 ';' 1 ';' 50 '; ' 75 '};
> v=zeros(size(s));
> for idx=1:length(s), v(idx)=str2num(s{idx});
> end
>
> I need that the sequence of the stimuli is respected as it appears on my file. There are more than 1000 data point in my coloumn, I would need to input the whole coloumn if you know what I mean.
>
> My array is stim and I tried to do soemthing like s={stim};
> but it prints this:
> {1403x1 cell}
> and if I run your script I get this error:
>
> >> s={stim};
> >> v=zeros(size(s));
> for idx=1:length(s), v(idx)=str2num(s{idx});end
> ??? Error using ==> str2num at 33
> Requires string or character array input.
>
> This is a very annoying problem..
> Thanks a lot guys for helping me!
>
> Alessandra

did you try the ...other... solution(?)...

us
From: Alessandra on
well,
this solution:

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)

gives me the array r with all sort of other numbers, I think it mixes up the two coloumn of my vector. It's not quote it.

I give you the first rows of my txt file, it might help:

R128 90.087400
R128 92.087400
R128 94.087400
R128 96.087400
S254 96.100200
R128 98.087400
S 50 99.115600
R128 100.087400
S 50 101.181200
R128 102.087400
S 50 103.263600
R128 104.087400
S 50 105.329400
R128 106.087400
S100 107.411800
R128 108.087400
S 50 109.494200
R128 110.087400
S 50 111.576600
R128 112.087400
S 50 113.642200
R128 114.087400
S 75 115.724600

you see, in the first coloumn I have the stimuli or markers and in the second the time when they appear.

Alessandra
From: us on
Alessandra <danda.galli(a)gmail.com> wrote in message <658936373.7743.1278796675389.JavaMail.root(a)gallium.mathforum.org>...
> well,
> this solution:
>
> 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)
>
> gives me the array r with all sort of other numbers, I think it mixes up the two coloumn of my vector. It's not quote it.
>
> I give you the first rows of my txt file, it might help:
>
> R128 90.087400
> R128 92.087400
> R128 94.087400
> R128 96.087400

> you see, in the first coloumn I have the stimuli or markers and in the second the time when they appear.
>
> Alessandra

it is pretty stupid to not give the correct anatomy of your file's content in your OP and, therefore, carelessly waste CSSMers' time(!!!!!)...

in your OP you showed this pattern...
S 75
S100
S 50
S 1
S128

be considerate when you post...

us