Prev: object detection
Next: maxNumCompThreads Replacement?
From: Steven Lord on 30 Mar 2010 09:49 "Maria_tab Manioudaki" <Belladonna_98(a)hotmail.com> wrote in message news:hosje6$ai1$1(a)fred.mathworks.com... > "us " <us(a)neurol.unizh.ch> wrote in message > <hosipk$1lh$1(a)fred.mathworks.com>... >> "Maria_tab Manioudaki" <Belladonna_98(a)hotmail.com> wrote in message >> <hosh54$8eg$1(a)fred.mathworks.com>... >> > I imported my data with the command importdata(filename) >> > and return a struct s.a with the headlines and the headcolumns of my >> > data and s.b with the rest numeric data. >> > I want to turn the structure into a single matrix again. >> > How do I do this? >> > Thank you >> >> a hint: >> >> help struct2cell; >> help cell2mat; >> >> us > > The s.b file has the form > A A1 A2 A3... > B [] [] [] > B1 [] [] [] > B2 [] [] [] > . > > when i use cell2mat i have an error that contents are not of the same type That is correct. An array in MATLAB can only contain data of one type; you can't have an array that is partly numeric data and partly char data. You have a couple of options: 1) Convert the char data into numeric (double) data and store the whole matrix as a double array. This will not work if your char data contains multi-character strings, or pad your numeric data to have 'blank' lines where the 2nd, 3rd, etc. characters of the strings are located. The string 'A1' is a 2-element char row vector, so to combine it with a numeric array with 'A1' as the header the numeric array would need to have 2 columns, not one. 2) Convert the numeric data into char data and store the whole matrix as a char array. If your numeric data contains numbers that can't be represented as nonnegative integers, you will lose precision. 3) Store your data in a cell array. This may seem like it's violating the rule I quoted above, but it's not -- the elements of the cell array are all of type cell. The contents of each _individual_ cell can be different, however. 4) If you have Statistics Toolbox, you could use the dataset object included in that toolbox (introduced a couple of releases ago) to give yourself named rows and columns. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ |