How can i changethe value at a position in an array
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, i wanted to cahnge some values in an array but could not do it, can you help me? Thanks in advance.
k=zeros(201);
k(0)=0;
k(101)=1;
k(201)=2;
댓글 수: 0
채택된 답변
Star Strider
2021년 6월 20일
The ‘k’ array is a (201x201) array of zeros. The code likely works correctly, however using a single index into an array uses linear indexing. To understand the row and column assignments for element 101 and 201, use the ind2sub function:
k = zeros(201)
k(101)=1;
[r1,c1] = ind2sub(size(k), 101)
k(r1,c1)
k(201)=2;
[r2,c2] = ind2sub(size(k), 201)
k(r2,c2)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!