필터 지우기
필터 지우기

Different value putting on different columns in matrix

조회 수: 1 (최근 30일)
Soumili Sen
Soumili Sen 2020년 12월 1일
댓글: Soumili Sen 2020년 12월 1일
Hello,
I am writting a matrix
p=zeros(4,5) -----> all column values are zero
but I want different values of different column like, 1st column's every value will be 2, 2nd column's every value wil be 0.25. similarly rest columns will be assigned by other values . How I can write this code.
Thanks in advance.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 1일
편집: Ameer Hamza 2020년 12월 1일
You can use repmat()
x = [2 0.25 3 1 7];
n_rows = 4;
M = repmat(x, n_rows, 1)
Result
>> M
M =
2.0000 0.2500 3.0000 1.0000 7.0000
2.0000 0.2500 3.0000 1.0000 7.0000
2.0000 0.2500 3.0000 1.0000 7.0000
2.0000 0.2500 3.0000 1.0000 7.0000
Or automatic array expansion
x = [2 0.25 3 1 7];
n_rows = 4;
M = x.*ones(n_rows,1);
Both are equivalent.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by