Hi,
Is there a single-step way to concatenate two vectors along the singleton dimension? For example, a 10x1 vector and a 1x25 vector. In some of my scripts the dimensions seem to be unpredictable for reasons I don't feel like digging into, and I have to use reshape every time I want to concatenate.
Thanks.

댓글 수: 2

David McVea
David McVea 2016년 7월 14일
As clarified below:
Thanks - I wasn't clear in my question.
I don't know whether the dimension would be 10x1 and 25x1, or 1x10 and 25x1, or any other combination.
All I know is they will both have a singleton dimension.
Stephen23
Stephen23 2016년 7월 14일
In your mind you might know what you want, but our crsytal balls are a little foggy today. Please give us some examples with both input and output vectors so that we can test our code with.

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 14일

0 개 추천

A=rand(5,1)
B=rand(1,4)
out=[A(:);B(:)]

댓글 수: 4

David McVea
David McVea 2016년 7월 14일
Thanks - I wasn't clear in my question.
I don't know whether the dimension would be 10x1 and 25x1, or 1x10 and 25x1, or any other combination.
All I know is they will both have a singleton dimension.
Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 14일
편집: Azzi Abdelmalek 2016년 7월 14일
do you mean the same dimension? if yes how to complete the missing data?
As far as I understand, Azzi's answer fills the brief. It reshapes both vectors into column vectors and concatenate them vertically. It therefore does not matter which dimension is the singleton one.
Of course, having code that generates vectors of unpredictable shape is not a good design, so I would fix that first. It could simply be forcing the output to be a column vector with:
out = out(:);
David McVea
David McVea 2016년 7월 14일
Yes, I am sorry. Azzi's answer is essentially what I am looking for. And it does bother me that the shape is unpredictable, but I have spend some time trying to track down the source but haven't figured it out yet. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2016년 7월 14일

댓글:

2016년 7월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by