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!