Concatenating Arrays with Different Dimensions
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm trying to concatenate these arrays with one line of code. How do I go about doing that?
The final array was supposed to be 3 x 4. I tried using the cat command, but because the dimensions are different, I had trouble doing it.
x = rand(1,3)
x = 10*x
x = round(x)
y = rand(1,3)
y = 10*y
y = round(y)
z = rand(1,4)
z = 10*z
z = round(z)
q = rand(2,1)
q = 10*q
q = round(q)
댓글 수: 0
채택된 답변
John D'Errico
2018년 9월 24일
You can want to do all sorts of things that are not possible to do.
But you cannot create a double precision array that has a varying amount of elements in each row or column. Arrays are RECTANGULAR things. So an array that has 3 elements in one row, and 4 elements in another will fail to work. It is invalid syntax to try to construct such a thing. Wanting is insufficient, unless of course, you will also decide to rewrite MATLAB from scratch. (Have fun with that.)
You COULD decide to pad zeros, or perhaps NaNs to some of those vectors as necessary, so they are all the same lengths. Or, you could use a cell array to store the vectors.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!