From: Joao on 10 Aug 2010 14:18 Hi all, The following cell2mat error is driving me nuts: ??? Error using ==> cat CAT arguments dimensions are not consistent. Error in ==> cell2mat at 89 m{n} = cat(1,c{:,n}); I have a file, input.txt, that has the names of around 4000 other files which I want to open and read. I'm using the following commands: [fid, message] = fopen('Input.txt'); [Data] = textscan(fid,'%s'); Filesname = cell2mat(Data{1,1}); fclose(fid); Does anyone has an idea why this error is happening, I've no clue. Thanks in advance Joao
From: Andy on 10 Aug 2010 14:24 "Joao" <janeiro.jm(a)gmail.com> wrote in message <i3s54t$m7a$1(a)fred.mathworks.com>... > Hi all, > > The following cell2mat error is driving me nuts: > > ??? Error using ==> cat > CAT arguments dimensions are not consistent. > > Error in ==> cell2mat at 89 > m{n} = cat(1,c{:,n}); > > > I have a file, input.txt, that has the names of around 4000 other files which I want to open and read. I'm using the following commands: > > [fid, message] = fopen('Input.txt'); > [Data] = textscan(fid,'%s'); > Filesname = cell2mat(Data{1,1}); > fclose(fid); > > Does anyone has an idea why this error is happening, I've no clue. > > Thanks in advance > > Joao cell2mat is intended for cell arrays whose elements are double arrays. Your Data{1,1} apparently is not a cell array of double arrays. And it is unlikely your intention to have a numeric array of file names.
From: Sean on 10 Aug 2010 14:24 "Joao" <janeiro.jm(a)gmail.com> wrote in message <i3s54t$m7a$1(a)fred.mathworks.com>... > Hi all, > > The following cell2mat error is driving me nuts: > > ??? Error using ==> cat > CAT arguments dimensions are not consistent. > > Error in ==> cell2mat at 89 > m{n} = cat(1,c{:,n}); > > > I have a file, input.txt, that has the names of around 4000 other files which I want to open and read. I'm using the following commands: > > [fid, message] = fopen('Input.txt'); > [Data] = textscan(fid,'%s'); > Filesname = cell2mat(Data{1,1}); > fclose(fid); > > Does anyone has an idea why this error is happening, I've no clue. > > Thanks in advance > > Joao Try transposing: Filesname = cell2mat(Data{1,1}');
From: Matt Fig on 10 Aug 2010 14:50 Did you look at what was in Data? It is probably strings with different lengths. Thus you cannot make an array because each row would have a different number of columns. Why not just use: [fid, message] = fopen('Input.txt'); [Data] = textscan(fid,'%s'); Data = Data{1}; Then whenever you need to open one of the files, say the 3rd one, just do: fopen(Data{3}); If you really want a character array for some reason, white-space and all, use: [fid, message] = fopen('Input.txt'); [Data] = textscan(fid,'%s'); char(Data{1})
|
Pages: 1 Prev: Fitting distribution to data Next: Safe file mutex without race condition |