Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Cell2mat issues

Subject: Cell2mat issues

From: João

Date: 10 Aug, 2010 18:18:05

Message: 1 of 4

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

Subject: Cell2mat issues

From: Andy

Date: 10 Aug, 2010 18:24:22

Message: 2 of 4

"Joao" <janeiro.jm@gmail.com> wrote in message <i3s54t$m7a$1@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.

Subject: Cell2mat issues

From: Sean

Date: 10 Aug, 2010 18:24:22

Message: 3 of 4

"Joao" <janeiro.jm@gmail.com> wrote in message <i3s54t$m7a$1@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}');

Subject: Cell2mat issues

From: Matt Fig

Date: 10 Aug, 2010 18:50:09

Message: 4 of 4

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})

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us