How do I check if the current value in an array is equal to 0 when looping? MatLab
이전 댓글 표시
Hello I'm new to using MatLab and don't know the syntax etc. very well. I know that some of my values will be zero for both zeta variables and height at some point in the below code.
xVelocity(i,j) = zetaU(i,j)/height(i,j);
yVelocity(i,j) = zetaV(i,j)/height(i,j);
How can I check if the values for these are zero and skip those that are?
답변 (1개)
David Hill
2022년 3월 4일
Perform all calculations at once, then determine how you want to handle the 0's.
xVelocity = zetaU./height;
yVelocity = zetaV./height;
idx1=xVelocity==0|xVelocity==inf;
idx2=yVelocity==0|yVelocity==inf;
xVelocity(idx1|idx2)=[];%I assume you want to delete those points
yVelocity(idx1|idx2)=[];
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!