Prev: imwrite cmyk tif bitmap file error
Next: Fitting data and then accessing sse, rsquare, dfe, adjrsquare
From: John on 28 Jun 2010 16:58 Howdy! I'm a NooB, but am making strides. This is my first line casted to MATLAB Central! I am presented with the following 1x45 cell array: [double] [double] [double] {cell} [double] ... [double] -- note the curly brackets around {cell}...why is that? Every sub-array is a 1000x1 column vector. Cells 1-3, and 5-45 all contain numeric data. Cell 4, on the other hand, contains #NAME? and seems to be interpreted as a cell. *** I would like to convert this cell array to a 1000x45 matrix. If all the sub-arrays were [doubles], then the function CELL2MAT would work perfectly. However, since one of my sub-arrays is a {cell}, CELL2MAT doesn't seem to work. How do I turn this Cell Array into a Matrix? Is there a simple find/replace type function to look for #NAME? (a string) and replace it with NaN (which is a double in MATLAB)? *****(I was thinking that somehow changing #NAME? to NaN might work but not sure how to do this in a Cell Array).***** Thanks for the help! -NOOB
From: Christopher on 29 Jun 2010 00:47
"John " <jfishbac(a)gmail.com> wrote in message <i0b2cv$6kr$1(a)fred.mathworks.com>... > Howdy! > > I'm a NooB, but am making strides. This is my first line casted to MATLAB Central! > > I am presented with the following 1x45 cell array: > > [double] [double] [double] {cell} [double] ... [double] > -- note the curly brackets around {cell}...why is that? > > Every sub-array is a 1000x1 column vector. Cells 1-3, and 5-45 all contain numeric data. Cell 4, on the other hand, contains #NAME? and seems to be interpreted as a cell. > > *** I would like to convert this cell array to a 1000x45 matrix. If all the sub-arrays were [doubles], then the function CELL2MAT would work perfectly. However, since one of my sub-arrays is a {cell}, CELL2MAT doesn't seem to work. > > How do I turn this Cell Array into a Matrix? > > Is there a simple find/replace type function to look for #NAME? (a string) and replace it with NaN (which is a double in MATLAB)? > > *****(I was thinking that somehow changing #NAME? to NaN might work but not sure how to do this in a Cell Array).***** > > Thanks for the help! > > -NOOB Strange problem John, not sure why a single cell would be a cell itself but anyway. If you wish to turn all cell type into a 1x1000 array of type double with the value NaN then determine which elements are cell and simply change them. Let's say your original 1x45 cell array is named origArray: for i = 1:length(origArray) if iscell(origArray{i}) origArray{i} = NaN*ones(1,1000); end end wantedMatrix = cell2mat(origArray); or simply for your problem, you know where the "bad" cell is so: origArray{4} = NaN*ones(1,1000); wantedMatrix = cell2mat(origArray); Not sure if this is the desired solution for you but thats how to change your pesky cell into NaN with dimensions consistent with the rest... |