Specific values in an Array

1 回表示 (過去 30 日間)
ILAYDA GULSEN KOCAK
ILAYDA GULSEN KOCAK 2021 年 5 月 18 日
編集済み: ILAYDA GULSEN KOCAK 2021 年 5 月 19 日
Hi guys. I want to select specific values from an matrix array and use this values in further calculations.
lets say I have the following code:
R=[];
for i=1:1:5
for y=5:1:10
eq1=i*y
%% To save the values:
R=[R; i y eq1]
end
end
%% The "R" Array would be like this:
1 5 5
1 6 6
1 7 10
1 8 8
1 9 9
1 10 10
2 5 10
2 6 12
...
Now I want to select only the y value when eq1 is equal to 10 and save it in another variable. I hope you can help me.

回答 (1 件)

per isakson
per isakson 2021 年 5 月 18 日
編集済み: per isakson 2021 年 5 月 18 日
R=[];
for i=1:1:5
for y=5:1:10
eq1=i*y;
%% To save the values:
R=[R; i y eq1];
end
end
another_variable = R( R(:,3)==10, 2 )
another_variable = 2×1
10 5
"%% The "R" Array would be like this:" Whether that's true depends on the meaning of "like this".
  1 件のコメント
ILAYDA GULSEN KOCAK
ILAYDA GULSEN KOCAK 2021 年 5 月 19 日
編集済み: ILAYDA GULSEN KOCAK 2021 年 5 月 19 日
Thank you for your answer. I'm working with iterations and therefore I dont get even numbers. Is there also a way to save the y value of every loop when its closest to 10? (I must become one value for every loop).
I woul also very appreciate if you could show me how to select the last y value of every loop.

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

カテゴリ

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