Combining variables
4 views (last 30 days)
Show older comments
I have written a code that generates 20 strings (the number actually varies depending on the input), all of which have the names "s_idx_?" where ? is a number from 1 to 20. Is there a command that allows me to concatenate all these strings without having to type out all the names? Thanks.
Accepted Answer
Sean de Wolski
on 19 Jul 2011
1 Comment
Jan
on 20 Jul 2011
I agree with "Don't do it". The SPRINTF command concatenates the _names_ of the variables?! The OP wants to cat the string values.
More Answers (1)
Jan
on 20 Jul 2011
Follow Sean's link to the FAQ. There you find the suggestion to use a cell like "s_idx{i}" instead of including the index in the name of the variables. Thjen the concatenation is easy:
s = cat(2, s_idx{:});
See Also
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!