How do I check if the current value in an array is equal to 0 when looping? MatLab
Show older comments
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)
David Hill
on 4 Mar 2022
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)=[];
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!