How can I make this matrix function?

1 回表示 (過去 30 日間)
minsoo kim
minsoo kim 2018 年 2 月 5 日
回答済み: Harish Ramachandran 2018 年 2 月 8 日
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
Harish Ramachandran 2018 年 2 月 8 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!