I have a matrix which has with some rows and 3 columns. Each element of the matrix is a number. I want to add a new column to this matrix with each entry as a string 'abc'. How can i do that ?
1 view (last 30 days)
Show older comments
a=[1 4 5 ; 2 5 7];
I want to add a fourth column to my matrix such that each element of the 4th column should be a string 'abc'. Output should look like:
a=[1 4 5 ; 2 5 7 ; abc abc abc]
0 Comments
Answers (2)
Guillaume
on 11 May 2018
That is not possible. A matrix is an homogeneous container. Every element is the same type. You can use non-homogeneous containers instead, such as a cell array:
a = [1 4 5 ; 2 5 7];
a = [num2cell(a); repmat({'abc'}, 1, size(a, 2))]
See Also
Categories
Find more on Data Type Conversion 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!