HOW to make constant values as new colum vector with the same values in my matrix
10 views (last 30 days)
Show older comments
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
please help
HOW to make constant values as new colum vector with the same values in my matrix
thank you
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Construction 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!