Ignore answers with imaginarey components

1 回表示 (過去 30 日間)
Justin Bruh
Justin Bruh 2016 年 11 月 1 日
編集済み: Thorsten 2016 年 11 月 1 日
I have a for loop nested inside of another for loop. I am using each for loop to vary a specific number (i.e A and B) to get every possible of combination of them and a corresponding result (C). I end up with a matrix of 3 columns and thousands of rows. I need to find the highest value of C. However all values of C with imaginary components are invalid. Can MATLAB eliminate all the values of C with imaginary components and their corresponding values of A and B to give me a new, and much smaller, matrix?

回答 (2 件)

KSSV
KSSV 2016 年 11 月 1 日
doc isreal
On using isreal output is a logical 1 if number is real and logical 0 if number is complex. Call isreal on the array which gives 1 and 0 from there eliminate all 0 s which gives you only real.

Thorsten
Thorsten 2016 年 11 月 1 日
編集済み: Thorsten 2016 年 11 月 1 日
This is basically the implementation of Dr. Siva Srinivas Kolukula's answer:
ind = ~isreal(C);
A(ind) = [];
B(ind) = [];
C(ind) = [];

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by