Trying to build a new nx4 array from an existing nx4 array using logical values

1 回表示 (過去 30 日間)
Michael Costa
Michael Costa 2021 年 6 月 3 日
編集済み: James Tursa 2021 年 6 月 8 日
I have a large nx4 array of quaternions (quatAB). I also have an nx1 array of energies (en) associated with the quaternions i.e. the nth quatAB corresponds to the nth en.
I have used MATLAB's islocalmin function on the energy array to return logical values. This returns a True (1) value if the energy (en) value is a local minimum, and a False if the energy is not a local minimum. After creating the nx1 array of logical values, I applied it to the en array to build a new en array of the local minimum energy values. Now, I want to do the same thing with the quaternions, but I am only getting the first column of each row, and i need all 4 columns.
min = islocalmin(en, 'MinProminence',1);
min_en = en(min);
min_quatAB = quatAB(min);
This successfully identifies the rows of the quaternions that I want to output, but when I apply the logical values, I'm only getting the first column element of each.

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 6 月 3 日
Don't use MATLAB's builtin function and comamnd names for variables, e.g.: min is builtin fcn of MATLAB.

James Tursa
James Tursa 2021 年 6 月 8 日
編集済み: James Tursa 2021 年 6 月 8 日
Assuming quatAB is a standard numeric matrix, use your logical variable for the first index and colon for the second index:
m = islocalmin(en, 'MinProminence',1);
min_en = en(m);
min_quatAB = quatAB(m,:);

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by