# HOW to make constant values as new colum vector with the same values in my matrix

19 views (last 30 days)
Budoor Salem on 21 Feb 2021
Commented: Budoor Salem on 21 Feb 2021
I wanted to create a dataset out of my code 'I have some constant values that I would like them to be repeated as a column in my matrix
HOW to make constant values as new colum vector with the same values in my matrix
thank you

KALYAN ACHARJYA on 21 Feb 2021
Edited: KALYAN ACHARJYA on 21 Feb 2021
Example:
Define Constant Values
const1=10;
const2=4;
const3=6;
Create the 1D Vector with Constant Values, consider any rows number, here considering 5
col1=const1*ones(5,1);
col2=const2*ones(5,1);
col3=const3*ones(5,1);
% Repeat the colums 5 times
Merge the all Columns
merge_mat=[col1,col2,col3];
Once the merge done, copy the same (five times) matrix in both ways horizantly and vertically
result=repmat(merge_mat,5)
More simpler, directly
const1=10;
const2=4;
const3=6;
result=repmat([const1,const2,const3],5)
More: If you want it to be repeated with specific shapes with the same matrix horizontally only
result=repelem([col1,col2,col3],1,5)
%.................................^ 5 times repetition columns
% Here 1 represents one time repetetion of rows, 5 times of columns.
Budoor Salem on 21 Feb 2021
Thank you so much , it works :D