0

I am trying to insert a value into Matlab vector like this:

 P = [ P(1:pos) point P(pos+1:end-1) ];

Yet I keep getting this error:

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

Error in ==> main at 65
 P = [ P(1:pos) point P(pos+1:end-1) ];

There is end-1 because I red that error above have something to do with arrays limits mismatch.

P.S. I know that value insertion into arrays is pretty common issue yet this seams to be the simplest way to do it and I really would like to understand why it would not work.

0

1 Answer 1

1

This statement is attempting to concatenate horizontally

P = [ P(1:pos) point P(pos+1:end-1) ]

But your vector P is a column vector.

What you need is a row vector, so transpose P first

P=P';
Sign up to request clarification or add additional context in comments.

3 Comments

It is sufficient to cat vertically then, using ;
@Acrobe, yes P=vertcat(P(1:pos), point, P(pos+1:end-1)), but my personal taste would be to use the easiest statement to type which is to use the [] syntax.
@jerad, well, indeed I ment something way easier like P = [P(...) ; p ; P(...)]..;)

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.