How can I convert matrix to cell array of strings?
Show older comments
I want to convert the following:
mat = [1 2 3; 4 5 6 ; 7 8 9];
into the following array of strings,
arr = {'1,2(3)', '4,5(6)', '7,8(9)'};
How can I do that?
1 Comment
Since R2016b:
mat = [1,2,3; 4,5,6; 7,8,9];
compose('%u,%u(%u)',mat)
Accepted Answer
More Answers (1)
KSSV
on 3 Oct 2017
mat = [1 2 3; 4 5 6 ; 7 8 9];
arr = {'1,2(3)', '4,5(6)', '7,8(9)'};
nx = size(mat,1) ;
iwant = strcat(num2str(mat(:,1)),',',num2str(mat(:,2)),repelem('(',nx,1),num2str(mat(:,3)),repelem(')',nx,1))
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!