combine a cell value with a number in matlab

You can use the num2str function to convert the number to a string, and then concatenate it with the cell value using square brackets. Here's an example:

main.m
% create a cell array
mycell = {'hello', 'world', '!'};

% concatenate cell value with a number
newcell = [mycell{1}, num2str(123)];

% display the result
disp(newcell);
170 chars
9 lines

This will output:

main.m
hello123
9 chars
2 lines

Note that the curly braces ({}) in the indexing of mycell are used to access the contents of the cell. Without them, you would get a cell array of 1x1 with the original cell inside.

related categories

gistlibby LogSnag