concatenate values from matrix and cell array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elysi Cochin
el 3 de Abr. de 2019
Comentada: madhan ravi
el 3 de Abr. de 2019
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 comentarios
Respuesta aceptada
Stephen23
el 3 de Abr. de 2019
>> 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 comentarios
Más respuestas (1)
madhan ravi
el 3 de Abr. de 2019
strcat(""+mtric,{'-'}, string(cell_array)) % string array
cellstr(strcat(""+mtric,{'-'}, string(cell_array))) % cell array
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!