Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
index in matrix using loop
조회 수: 1 (최근 30일)
이전 댓글 표시
hi i have an matrix in my code that i want to do some calculation on each index in it so first of all i want to check if that index is greater then 0 then i multiply by area then store it in new varible calld fill
if not i multiple this index with area then store it in variable calld fill
how can i do it
댓글 수: 3
dpb
2019년 4월 28일
I'd guess it mandatory to give an example or at least clarify because as written the result is the same for either case...
답변 (1개)
Kevin Phung
2019년 4월 30일
m = [0.5 0.5; 0.25 0.5; -0.5 -0.5] % your sample matrix
f = m(m>0) * A + fill
c = m(m<0) *A + cut
^ this only return the values that meet the positive/neg criteria. If you want to keep the same dimensions then do this:
new_m = m; %copy
new_m(m>0) = m(m>0) * A + fill; %operate on positives
new_m(m<0) = m(m<0) * A - cut;
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!