Filter löschen
Filter löschen

??? Error using ==> horzcat, CAT arguments dimensions are not consistent.

2 Ansichten (letzte 30 Tage)
Zach
Zach am 30 Mär. 2012
I have two cell arrays, both of length n. One array contains nX1 strings, while the other array is contains nx1 type double. I'm trying to create a new variable that is nx2.
The error doesn't seem to make sense to me, since the dimensions of both arrays are identical. This is probably a novice error, so I'll lay out exactly what I've done:
A = {a, b, c, d, ..., n}
B = {1,2,3,4....n}
C = [A,B]
??? Error
If I attempt this:
C = [A;B]
The new variable that is created is (n+1)x1 containing all of the cells in A plus a new cell with text (nx1 double), but lacking any of the values stored within B.
A and B are variables that have been imported using xlsread
If anyone can help me with the problem and shed some light on why exactly this is happening I would greatly appreciate it. Thank you.

Antworten (1)

Thomas
Thomas am 30 Mär. 2012
you should try
A = {'a', 'b', 'c', 'd'}
B={1,2,3,4}
C=[A,B];
D=[A;B];
Make sure A and B are being declared as cells.
  1 Kommentar
Zach
Zach am 30 Mär. 2012
Thanks for the response.
The issue that I have is that I'm not defining A or B.
That is to say, they are being imported using xlsread, so really
A = <n x 1 cell>
and
B = <n X 1 double>
with text and number information as imported from excel. Rewriting the data in A by hand to include '' is tedious, as there are 300+ worksheets that I'm attempting to analyze data from, and n ranges from ~10 to 40, with no consistency.
To be clear, I don't really care about D = [A;B]. I just left it in because MatLab allowed that combination to happen without giving me the error message. I'm assuming that it had something to do with recognizing B = <nx1 double> as a string and simply adding it to the array A = <nX1 cell>, that contains strings.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by