필터 지우기
필터 지우기

how can I tell MATLAB to add a NaN if the size of concatenation is not consistent?

조회 수: 3 (최근 30일)
Lets say I have two matrices: A = [2,2;3;3] and B = [4,4,4;5,5,5]
I was trying to concatnate them by doing: C = [A; B]
But MATLAB threw an error saying that the dimensions are not consistent.
Now whats an easy way to fix this? The result that I would like from the example I gave previously is: C = [2,2,NaN; 3,3,NaN; 4,4,4; 5,5,5]
  댓글 수: 1
Florian Rössing
Florian Rössing 2023년 1월 18일
You could write your own function that does length matching before concatenating. Appart from that, no Idea

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

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 1월 18일
A = [2,2;3,3];
B = [4,4,4;5,5,5];
A=padarray(A,[0 1],nan,'post')
A = 2×3
2 2 NaN 3 3 NaN
C=[A;B]
C = 4×3
2 2 NaN 3 3 NaN 4 4 4 5 5 5

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by