indexing complex numbers

hi,
I'm trying to index the arrays of as explained below.
a = [-1+i 1+i 1+i 1+i -1+i -1-i -1+i 1+i 1-i -1+i -1-i -1+i -1-i -1-i -1+i -1-i]
b = [00 01 11 10]
-1+1 will be replaced by 00
1+i will be replaced by 01
1-i will be replaced by 11
-1-i will be replaced by 10
the problem is that, any method of indexing i try gives me the same error message saying "Subscript indices must either be real positive integers or logicals." Pls i dnt knw wat to do.
Thanks in advance

 採用された回答

Rick Rosson
Rick Rosson 2011 年 11 月 25 日

0 投票

x = ( 1 + real(a) ) / 2;
y = ( 1 - imag(a) ) / 2;
b = [ y ; x ];

3 件のコメント

deji
deji 2011 年 11 月 25 日
thanks.. will dis work for only complex numbers like 1+i, 1-i, -1+i and -1-i? or will it work with all sorts of complex numbers
Walter Roberson
Walter Roberson 2011 年 11 月 25 日
It will only work for +/-1 +/-1*i . If you have other fixed sets of values with fixed mappings, sometimes you can create simple mapping expressions like Rick shows, and sometimes you cannot.
deji
deji 2011 年 11 月 27 日
i tried the ,method for complex numbers like 2.2631+2.2631i, 2.2631-2.2631i, -2.2631+2.2631i and -2.2631-2.2631i but it didnt work.. wat method can be used for this

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2011 年 11 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by