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?

Answers (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)=[];

Products

Release

R2021b

Asked:

on 4 Mar 2022

Answered:

on 4 Mar 2022

Community Treasure Hunt

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

Start Hunting!