seperation columns when one string in number other is txt.

1 view (last 30 days)
names=['john'; 'ravi'; 'mary'; 'xiao']
howdy=char('10', '20', '30')
result=[howdy(2,:) names(3,:)]
result=20mary
I wanna create "20 marry" with spaces between columns, how can I add the spaces between the columns?

Accepted Answer

Image Analyst
Image Analyst on 27 May 2013
result=[howdy(2,:), ' ', names(3,:)];
or use sprintf(), like I prefer:
result = sprintf('%s %s', howdy(2,:), names(3,:));
By the way, if any names are not exactly the same length as the others, then you'll have to have names be a cell array, not a character array and you'll have to use braces, not parentheses, like I did here.
  4 Comments
Image Analyst
Image Analyst on 28 May 2013
Well you switched from rows like you started (and I answered) to columns. Look - the indexes inside howdy and a went from the first index being specified to the second index being specified. So now you're trying to stitch together horizontally vertical columns that have different heights. You can't do that because the matrix would no longer be rectangular - it would have an irregular bottom edge.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!