How do I turn a number array into a specific string set?

8 次查看(过去 30 天)
Hi,
I have an array of data (numbers) (set of 24) that I would like to turn into a string array and then add to a cell array (with a specified row) so it can be put into a GUI table. colorgen gives each specific cell a color background (given by the code http://www.mathworks.com/matlabcentral/answers/25038-how-to-change-each-cell-color-in-a-uitable). In order for this code to work the number data has to be a string. So for example, one element of the original array could be 722.845, which i would like to turn into '722.845', and then place into position data{3, 2}. But when I use the for loop, and get the numel (or size) or array_cell i get the number of characters in the array which is about ~300, and not 24 (which how many elements are in the original array) and the table prints out each character into one box. Help!
array_cell = num2str(array);
for i=1:numel(array_cell) %size(array_cell,2)
data{row,i+1} = colorgen(color, array_cell(i));
end

采纳的回答

SL B
SL B 2013-5-16
array_cell = num2str(array) I think is the problem. Try using the num2str within the for loop.
for i=1:size(array,2)
data{row,i+1} = colorgen(color, num2str(array(i)));
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by