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

28 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 21 Feb. 2021
Bearbeitet: KALYAN ACHARJYA am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by