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개)

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에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 3월 4일

답변:

2022년 3월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by