Setting a limit in an array

15 ビュー (過去 30 日間)
Chris Brown
Chris Brown 2017 年 2 月 8 日
コメント済み: Chris Brown 2017 年 2 月 8 日
I am trying to set a limit for values within an array between a set of point. I have a 3D array - say 100x100x100.
I want to set a limit of 30, so if the values are lower they become 30. I also only want to apply the values between 40 and 50 in the z axis... I have tried a few methods, but can't seem to get it to work. Any help would be appreciated.
This is what I have tried so far..
for a=1:Ini
x=100;
y=100;
z=100;
i=2:x-1;
j=2:y-1;
k=40:z-50;
F(F(j,i,k)<30)=F(F(j,i,k)<30)./F(F(j,i,k)<30)+30;
end
and separately -
for a=1:Ini
x=100;
y=100;
z=100;
i=2:x-1;
j=2:y-1;
k=40:z-50;
idx=find(F(j,i,k)<30);
idx=(idx.*0)+30;
[i,j,k]=ind2sub(size(F),idx);
end
  2 件のコメント
Jan
Jan 2017 年 2 月 8 日
編集済み: Jan 2017 年 2 月 8 日
I do not understand "apply the values between 40 and 50 in the z axis". Where does this point appear in the code? What is Ini? Why do you look at 2:x-1 only and not at the margins?
Chris Brown
Chris Brown 2017 年 2 月 8 日
Sorry that wasn't clear. 40 and 50 referring to the z dimension - see k within the loop. Ini is number of iterations - this is part of a bigger loop, where each step I want to limit the data to 30 minimum.

サインインしてコメントする。

採用された回答

Alexandra Harkai
Alexandra Harkai 2017 年 2 月 8 日
Given initial matrix F, this will floor entries at 30 in between z 'axis' (from and including) 40 and 50:
F(:,:,40:50) = max( 30, F(:,:,40:50) );

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by