How can I make this matrix function?

1 次查看(过去 30 天)
Let's say I have a matrix A[x,y,z]
If A[i,j,k]<N, (i<=x, j<=y, k<=z, N : certain value.)
then A[i,j,k]=0
else nothing happens.
I can make this function if I use "for" statement, but using "for" statement in matlab consumes a lot of time.
I'm sure there is a function that best fits what I want to do.
So, How can I make this function without using "for" statement?

回答(1 个)

Harish Ramachandran
This is an example of your use case on a 2-D matrix. The same is scalable for a 3-D matrix.
X = rand(5)
X =
0.7577 0.7060 0.8235 0.4387 0.4898
0.7431 0.0318 0.6948 0.3816 0.4456
0.3922 0.2769 0.3171 0.7655 0.6463
0.6555 0.0462 0.9502 0.7952 0.7094
0.1712 0.0971 0.0344 0.1869 0.7547
X(X<0.5) = 0;
X =
0.7577 0.7060 0.8235 0 0
0.7431 0 0.6948 0 0
0 0 0 0.7655 0.6463
0.6555 0 0.9502 0.7952 0.7094
0 0 0 0 0.7547

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!