0

If I have a matrix

A = [0 1 0 1
     0 0 1 1]

and a variable B = 121.23, how can I concat both into a one variable.

I did

features_set = [A(:), B];

But, it gives an error CAT arguments dimensions are not consistent.

How can I add this variable B to the end of the vector A?

1 Answer 1

2

A(:) returns an 8-by-1 array. The comma appends along the second dimension. Thus, your code fails.

If the output should be a 9-by-1 array, you should write

features_set = [A(:);B];

If the output should be a 1-by-9 array, you should write

features_set = [A(:)',B];
Sign up to request clarification or add additional context in comments.

2 Comments

Or features_set = [A(:)' B]; of course, depending on whether you want a Nx1 or 1xN vector.
yeah.. I need 9-by-1 array. So, your first solution is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.