How do you change an entire row or column of an array to a certain value
조회 수: 43 (최근 30일)
이전 댓글 표시
If I have an array of all zeros X = zeros(N) How do I change a column to a value I want.
댓글 수: 0
채택된 답변
Star Strider
2017년 9월 15일
One option:
N = 5;
X = zeros(N);
X(:,3) = rand(N, 1); % Change Column #3 To A Specific Vector
X(2,:) = 5*ones(1, N); % Change Row #2 To a Row Of ‘5’
댓글 수: 4
Star Strider
2023년 9월 13일
@Riley Harris — Yes, however it can easily be vectorised. Using the sub2ind function is another option.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!