How can I make this matrix function?

1 visualización (últimos 30 días)
minsoo kim
minsoo kim el 5 de Feb. de 2018
Respondida: Harish Ramachandran el 8 de Feb. de 2018
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?

Respuestas (1)

Harish Ramachandran
Harish Ramachandran el 8 de Feb. de 2018
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

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!