0
votes

I have two matrices as A:

'1 2 3 4'     0.00959601005678583   4
'1 2 3'        0.00972420458014290  3
'1 2 4'        0.0107007400086486   3
'1 2'          0.0108439251050866   2

B:

2.20000000000000
1.91335914850010
2.01512388433582
1.73004520013173

Why cant i concatenate this horizontally using this function?

C=horzcat(A,B);

The error that shows is:

Error using horzcat Dimensions of matrices being concatenated are not consistent.

1
Are you sure it is two matrices? The first one looks more like a cell array?Stewie Griffin
Ya it is so. Actually I need to concatenate these two horizontally..How to do it?user2458552
Is the first one a cell or a matrix? Are the columns to the left in A chars? What are A(1) and A{1} and what do you get if you just type A?Stewie Griffin

1 Answers

1
votes

horzcat(A, B) works when A and B are both matrices, so it won't work here because A is (I am assuming) a cell array.

A cheap way to solve your problem is with a loop that adds values to A:

for ii=1:size(A,1)
    A{ii, 4} = B(ii);
end

Then your cell A would look like this:

A = 
    '1 2 3 4'    [0.0096]    [4]    [2.2000]
    '1 2 3'      [0.0097]    [3]    [1.9134]
    '1 2 4'      [0.0107]    [3]    [2.0151]
    '1 2'        [0.0108]    [2]    [1.7300]