finding places where an array are equal to zero and replacing them accordingly

4 ビュー (過去 30 日間)
Bran
Bran 2013 年 6 月 26 日
I have written some code, however, due to the fact that my alogirthm is really quite complicated it is hard for me to see if my code is working
I Have a 16x16x16 array and I want to find the places where that array = zero;
I have done this in the following way ind = A == 0
I then want to create a new array which takes values from one array at the places where it is zero and values from another else where; Would this code do it?
ANEW(ind)=Adashup2new(i,j,k);
ANEW(~ind) = MAT(i,j,k);
  2 件のコメント
Lokesh Ravindranathan
Lokesh Ravindranathan 2013 年 6 月 26 日
Could you provide an example of what you are attempting to do? I understand that you have found the indices where the values are zeros. Could you explain what the variables are, ANEW and Adashup2new w.r.t. A?
Bran
Bran 2013 年 6 月 26 日
So I want to create a new array called ANEW which has the same dimensions as A At the indices where A is zero I want it to instead take values from an array called Adashup2new and for all other indices I want it to take values from an array called MAT.

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

採用された回答

Image Analyst
Image Analyst 2013 年 6 月 26 日
Try this:
% Initialize ANEW to MAT.
ANEW = MAT;
% Find zero values;
zeroIndexes = A == 0;
% Replace ANEW values at zeroIndexes with values from Adashup2new
ANEW(zeroIndexes) = Adashup2new(zeroIndexes);
Adashup2new must be the same dimensions as A, ANEW, and MAT.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by