how to select a random row from an excel sheet which has 16801 rows and 28 columns ?

3 ビュー (過去 30 日間)
i have an excel sheet of 16801x28 and want to randomly select one row out of this to give it as a input to my kalman filter i just want to know how can i select a row randomly with a code instead of doing it manually ?
Thanks in advance

採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 8 日
num_row = size(YourArray, 1);
random_row_number = randi(num_row);
random_row = YourArray(random_row_number, :);
The compact version of this is:
random_row = YourArray( randi(size(YourArray,1)), :);
  3 件のコメント
Stephen23
Stephen23 2017 年 5 月 8 日
編集済み: Stephen23 2017 年 5 月 8 日
@Nana Fernandes: The variable random_row_number has the row number.
Nana Fernandes
Nana Fernandes 2017 年 5 月 8 日
編集済み: Walter Roberson 2017 年 5 月 8 日
thanks to all for the help

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

その他の回答 (1 件)

KL
KL 2017 年 5 月 8 日
rowNo = randi([1, 16801])
  2 件のコメント
Guillaume
Guillaume 2017 年 5 月 8 日
It's better not to hardcode the size but instead get it directly from the matrix that is going to be indexed. That way you're guaranteed that the code will work when inevitably the matrix change at some point in the future.
KL
KL 2017 年 5 月 8 日
I just had the presumption that it's understandable since the question says ..just want to know... Nevertheless you're totally right there!

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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by