필터 지우기
필터 지우기

Assign values to intervals of matrix

조회 수: 2 (최근 30일)
d7366431
d7366431 2020년 5월 14일
댓글: d7366431 2020년 5월 14일
Hi,
Could you please tell me how to assign values to each of 580 elements in the matrix.
Let say I have nx3 matrix and for the first 580 elements of 3rd column should be assigned value from the 1st element of the vecor t1 (mx1 size), for the next 580 elements of 3rd column should be assigned 2nd element of the vector t1.
I tried to implement it with the for loop, but the problem is how to iterate through the t1(z).
Thank you!
for i=1:580:length(A)
for k=1:580
A(i+k-1:i+k-1,3)=t1(z);
end
end

채택된 답변

John D'Errico
John D'Errico 2020년 5월 14일
편집: John D'Errico 2020년 5월 14일
Use MATLAB as it is designed to be used - as a language that works with vectors and matrices.
A(:,3) = repelem(t1,580);
  댓글 수: 1
d7366431
d7366431 2020년 5월 14일
Thank you! Just Genius! I didn't know about this function =)

댓글을 달려면 로그인하십시오.

추가 답변 (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