matlab - Most efficient way to store numbers as strings inside a table -
i want store efficiently numbers strings (with different lengths) table. code:
% table numbers n = 5; m = 5; t_numb = array2table((rand(n,m))); % create table empty cells (to store strings) t_string = array2table(cell(n,m)); = 1:height(t_numb) ii = 1:width(t_numb) t_string{i,ii} = cellstr(num2str(t_numb{i,ii}, '%.2f')); end end
what improve it? thank you.
i don't have access function cell2table
right now, using undocumented function sprintfc
might work here (check here details).
for instance:
%// 2d array = magic(5) b = sprintfc('%0.2f',a)
generates cell array this:
b = '17.00' '24.00' '1.00' '8.00' '15.00' '23.00' '5.00' '7.00' '14.00' '16.00' '4.00' '6.00' '13.00' '20.00' '22.00' '10.00' '12.00' '19.00' '21.00' '3.00' '11.00' '18.00' '25.00' '2.00' '9.00'
which can convert table using cell2table
.
so in 1 line:
yourtable = cell2table(sprintfc('%0.2f',a))
Comments
Post a Comment