From: James on
I have a 2756x1 cell array with twos compliment data in each cell as follows

'0007,0006,00fe'
'0006,0007,00fc'

And the list continues. I want to extract the first 4 digits as a string, second 4 and third 4. These will be x,y,z. i.e. x='0007' y='0006' z='00fe'. I can then convert these to decimal values (which I know how to do). How can I extact these values. Ideally I could do with three separate cell arrays containing strings rather that integers.

x=
'0007'
'0006'
etc...

y=
'0006'
'0007'
etc...
z=
'00fe'
'00fc'
etc...

Can anyone help?
From: Andy on
data={'0007,0006,00fe';
'0006,0007,00fc';
'0005,1234,ffff'};
x=cellfun(@(c) {c(1:4)}, data);
y=cellfun(@(c) {c(6:9)}, data);
z=cellfun(@(c) {c(11:14)}, data);
From: Nathan on
On Jan 13, 12:11 pm, "James " <jim....(a)btinternet.com> wrote:
> I have a 2756x1 cell array with twos compliment data in each cell as follows
>
> '0007,0006,00fe'
> '0006,0007,00fc'
>
> And the list continues.  I want to extract the first 4 digits as a string, second 4 and third 4.  These will be x,y,z. i.e. x='0007'  y='0006'  z='00fe'.  I can then convert these to decimal values (which I know how to do).  How can I extact these values. Ideally I could do with three separate cell arrays containing strings rather that integers.
>
> x=
>      '0007'
>      '0006'
>      etc...
>
> y=
>      '0006'
>      '0007'
>      etc...
> z=
>      '00fe'
>      '00fc'
>      etc...
>
> Can anyone help?

doc textscan

Example:
M = textscan(fid,'%s %s %s','delimiter',',');

Each column of M will be your corresponding x,y,and z arrays.

-Nathan
From: Matt Fig on
One approach:

% Data
G = {'0007,0006,00fe';'0003,0007,00gc';'0001,0002,00ac';'0003,0001,00xc'}

% Engine
x = cellfun(@(x)x(1:4),G,'Un',0)
y = cellfun(@(x)x(6:9),G,'Un',0)
z = cellfun(@(x)x(11:14),G,'Un',0)
From: James on
> x = cellfun(@(x)x(1:4),G,'Un',0)
> y = cellfun(@(x)x(6:9),G,'Un',0)
> z = cellfun(@(x)x(11:14),G,'Un',0)

This worked perfect for my needs. Thanks for the quick replies everyone. As for the sugestion of:

>M = textscan(fid,'%s %s %s','delimiter',',');

I had actually tried this before, but for some reason I had problems reading my csv file into the fid.

Thanks again all, and all the best for the rest of the year.

James