Putting Output values into a matrix.

5 ビュー (過去 30 日間)
Edward Steen
Edward Steen 2017 年 2 月 24 日
コメント済み: Star Strider 2020 年 11 月 27 日
Hi, I have an if statement within a double for loop. I would like to be able to put the two index values that satisfy the if statement into a matrix that I can then manipulate etc. Currently, I am just using "disp" to display the two index values. How can I go about putting the values into a matrix?

採用された回答

Star Strider
Star Strider 2017 年 2 月 24 日
編集済み: Star Strider 2017 年 2 月 24 日
One approach:
vals = [];
for k1 = 1:10
for k2 = 1:10
if k1 == k2 % Test Condition
vals = [vals; k1 k2]; % Store Index Values
end
end
end
Here, the ‘vals’ matrix will be:
vals =
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
  2 件のコメント
Rashfa Baalfaqih
Rashfa Baalfaqih 2020 年 11 月 27 日
What if I want to put a title for each column?
Star Strider
Star Strider 2020 年 11 月 27 日
Use array2table and then add the variable (column header) names.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by