Concatenating Arrays end to end 1D

조회 수: 14 (최근 30일)
Calum
Calum 2023년 8월 22일
댓글: Star Strider 2023년 8월 22일
Hi folks, I am trying to join some 1d arrays together, some with numbers and others with text, but running into some issues.
I have the following:
Blank='-';
FailureCode = 18;
Duplicates = [1;71;91;119;141;155;160;255];
a= cellstr(repmat(Blank, [FailureCode 1]));
e = cat(1, Duplicates, a)
e = 19×1 cell array
{8×1 double} {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' }
From this, it can be seen that the first cell is an 8x1 double. However I would like a full 1d array where the last value of duplicates joins to the first value of the repeated dash symbol array 'a'.
Hope someone can help!
Thanks,
Calum.

채택된 답변

Star Strider
Star Strider 2023년 8월 22일
One option is to convert ‘Duplicates’ to a cell array (using num2cell) to make it compatible with the other values —
Blank='-';
FailureCode = 18;
Duplicates = [1;71;91;119;141;155;160;255];
a= cellstr(repmat(Blank, [FailureCode 1]));
e = cat(1, num2cell(Duplicates), a)
e = 26×1 cell array
{[ 1]} {[ 71]} {[ 91]} {[119]} {[141]} {[155]} {[160]} {[255]} {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' } {'-' }
.
  댓글 수: 2
Calum
Calum 2023년 8월 22일
Hi Star Strider, thanks a lot. Was silly of me to overlook compatibility. This works perfectly!
C.
Star Strider
Star Strider 2023년 8월 22일
As always, my pleasure!
No worries! I needed to experiment with a couple different approaches to get it to work.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by