concatenate values from matrix and cell array
조회 수: 2 (최근 30일)
이전 댓글 표시
i have a matrix and a cell array
mtric =
1 2 3
4 5 6
7 8 9
cell_array =
aa bb cc
dd ee ff
gg hh ii
i wanted to combine both these as
new_out =
1 - aa 2 - bb 3 - cc
4 - dd 5 - ee 6 - ff
7 - gg 8 - hh 9 - ii
댓글 수: 0
채택된 답변
Stephen23
2019년 4월 3일
>> M = [1,2,3;4,5,6;7,8,9];
>> C = {'aa','bb','cc';'dd','ee','ff';'gg','hh','ii'};
>> F = @(n,c) sprintf('%d - %s',n,c{:});
>> Z = arrayfun(F,M,C,'uni',0)
Z =
'1 - aa' '2 - bb' '3 - cc'
'4 - dd' '5 - ee' '6 - ff'
'7 - gg' '8 - hh' '9 - ii'
댓글 수: 0
추가 답변 (1개)
madhan ravi
2019년 4월 3일
strcat(""+mtric,{'-'}, string(cell_array)) % string array
cellstr(strcat(""+mtric,{'-'}, string(cell_array))) % cell array
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!