Assign to cell elements with both string and number?

2 次查看(过去 30 天)
Hi ,
Could someone tell me how to assign to cell element with both string and number? For example with my simple code:
clc
close all
clear all
text={'STT'}
x=1:10
The result I want to get is
text{'STT';'1';'2';'3';...;'10'}
Thank you.

采纳的回答

Andrew Newell
Andrew Newell 2014-12-3
编辑:Andrew Newell 2014-12-3
You can use num2str to convert x to string; but you need to make it operate on one element of x at a time, or they will be bundled in one string. One approach is to use arrayfun:
text = [text; arrayfun(@num2str,x','UniformOutput',false)]
Note the transpose (') on the x, to make sure it is a column vector.
This answer was edited because I did not read the question correctly the first couple of times.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by