フィルターのクリア

I need to map a binary array to 2 differnet values corresponding to 0 & 1

1 回表示 (過去 30 日間)
Sagar  Saxena
Sagar Saxena 2018 年 6 月 29 日
編集済み: dpb 2018 年 6 月 30 日
A= zeros(320,320); A(60:180,60:180)=1;
lets say I wanna make all 1's = 2+3i and all 0's equals to 8-4i.
What would be the syntax to map them to corresponding values. Thanks

採用された回答

dpb
dpb 2018 年 6 月 29 日
編集済み: dpb 2018 年 6 月 30 日
One of a zillion ways...
C=complex(2*ones(size(A)),3*ones(size(A)));
C(C==0) = 8-4i;
Another less "deadahead" but one-liner...
C=interp1([0 1],[8-4i 2+3i],A,'nearest');
ADDENDUM
A variation on the latter is simple lookup...requires the temporary vector, though.
v=[8-4i 2+3i]; % the values
C=v(A+1); % convert logical to array indices

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by