Prev: Matlab Editor Sometimes Fails to Display Text in Ubuntu
Next: Matlab R14, Windows 7, and uicontrol objects
From: James on 13 Jan 2010 15:11 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 13 Jan 2010 15:24 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 13 Jan 2010 15:30 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 13 Jan 2010 15:32 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 14 Jan 2010 14:53 > 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
|
Next
|
Last
Pages: 1 2 Prev: Matlab Editor Sometimes Fails to Display Text in Ubuntu Next: Matlab R14, Windows 7, and uicontrol objects |