In an assignment A(I) = B, the number of elements in B and I must be the same error
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, I would like to know how to change the 0's in C that are in the same position where d1 finds values where (d<=d0) with the corresponding d value. d is a 100x1 array and d0 is the mean value. For instance if the first and fourth elements in d are less than d0, then the first and fourth elements in d are stored as the first and fourth elements in C respectively.
C=zeros(100,1);
d1=find(d<=d0);
C(d1)=d;
댓글 수: 0
채택된 답변
Image Analyst
2015년 4월 21일
Almost right. Try this instead:
C=zeros(100,1);
d1 = find(d<=d0);
C(d1)=d(d1);
추가 답변 (1개)
Star Strider
2015년 4월 21일
편집: Star Strider
2015년 4월 21일
Using ‘logical indexing’ works well here:
C = zeros(100,1);
d = randi(10, 100, 1);
d0 = mean(d);
C(d<=d0) = d(d<=d0);
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!