Matrices and indexing ?!

I have two variables with the same set of values Lx= (5,7,9,11,13,15) Ly=(5,7,9,11,13,15) and I want to tell Matlab to choose the combinations of Lx and Ly under the condition Lx/Ly =< 2 eg: 5*5 , 7*5, 7*7, 9*5, 9*7, 9*9 and so on, What should be written ? I don’t want it to multiply both numbers just a combination as they are to be used as inputs for the following steps

2 件のコメント

James Tursa
James Tursa 2020 年 2 月 11 日
What does "Lx/Ly = 2" mean? Your example doesn't seem to fit.
Ahmed Yassin
Ahmed Yassin 2020 年 2 月 11 日
Sorry, It’s a typo I meant less than or equal 2

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

回答 (1 件)

James Tursa
James Tursa 2020 年 2 月 11 日
編集済み: James Tursa 2020 年 2 月 11 日

0 投票

[LX,LY] = ndgrid(Lx,Ly);
z = LX(:)./LY(:) <= 2;
LX = LX(z);
LY = LY(z);
LX and LY contain the number pairs that match the condition.

カテゴリ

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

製品

リリース

R2019b

質問済み:

2020 年 2 月 11 日

編集済み:

2020 年 2 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by