필터 지우기
필터 지우기

Merging empty vector with double

조회 수: 2 (최근 30일)
Joel
Joel 2023년 4월 13일
답변: Stephen23 2023년 4월 13일
Hi
I have two vectors:
9x1
A=[1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9]
B=[]
I want to compare A and B in the same matrix. Like
9x2
C=[A B];
But B is empty, How can I display this in the same matrix?.
The length of the vectors will vary, so the number of rows in C should be the same as the longest vector out of A and B.
  댓글 수: 2
Stephen23
Stephen23 2023년 4월 13일
편집: Stephen23 2023년 4월 13일
"How can I display this in the same matrix?."
Display what exactly?
Numeric matrices cannot have "holes" in them, so what value/s would you put in the "empty" locations? By default, numeric matrices are filled with zeros, which then could not be distinguished from zeros from your actual data.
Joel
Joel 2023년 4월 13일
yes so if B is empty, I want it to be shown as 9 zeros or 9 ones if thats better

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

채택된 답변

Stephen23
Stephen23 2023년 4월 13일
"if B is empty, I want it to be shown as 9 zeros"
A = [1;2;3;4;5;6;7;8;9];
B = [];
C = [];
C(1:numel(A),1) = A;
C(1:numel(B),2) = B
C = 9×2
1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by