how do i join cell array strings for plotting

조회 수: 2 (최근 30일)
Adam Jurhs
Adam Jurhs 2023년 2월 1일
편집: Jan 2023년 2월 1일
hi,
i have a 2 by 3 cell array. the rows looks like:
{["abc\_111"]} {["def\_111"]} {["ghi\_111"]}
{["abc\_123"]} {["abc\_456"]} {["abc\_789"]}
what i think i want to do is join all the elements in each row into a column so that i can use them in making a plot with set(gca, 'xticklabels',joined_string). i think the new joined_sting should look like this
{["abc\_111\_def\_111\_ghi\_111"]}
{["abc\_123\_abc\_456\_abc\_789"]}
i'm both not sure if this is the right way to do this or how to do this. i've tried join and i keep gettign error messages
  댓글 수: 1
Jan
Jan 2023년 2월 1일
편집: Jan 2023년 2월 1일
The input format is strange: Strings inside a cell array? Either use a string array, or a "cell string", which is the historical term for a cell or char vectors. A cell of strings combines the drawbacks of both versions.

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

채택된 답변

Jan
Jan 2023년 2월 1일
편집: Jan 2023년 2월 1일
Dicide to use a better input format. Either a cell string:
C = {'abc\_111', 'def\_111', 'ghi\_111'; ...
'abc\_123', 'abc\_456', 'abc\_789'};
Or a string array:
S = ["abc\_111", "def\_111", "ghi\_111"; ...
"abc\_123", "abc\_456", "abc\_789"];
Then:
result = join(C, '\_', 2)
result = 2×1 cell array
{'abc\_111\_def\_111\_ghi\_111'} {'abc\_123\_abc\_456\_abc\_789'}
% or
result = join(S, '\_', 2)
result = 2×1 string array
"abc\_111\_def\_111\_ghi\_111" "abc\_123\_abc\_456\_abc\_789"

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by