フィルターのクリア

I need to remove randi from for loop

3 ビュー (過去 30 日間)
Neda
Neda 2018 年 1 月 28 日
回答済み: Image Analyst 2018 年 1 月 28 日
I need to remove randi from the for loop. Any help would appreciate.
I=30;
t1=randi([1 5],1,I);
t2=randi([6 10],1,I);
for i=1:I
TD(1,i)=randi([t1(1,i) t2(1,i)],1,1);
end
  2 件のコメント
Star Strider
Star Strider 2018 年 1 月 28 日
That seems easy enough to do, although it would be interesting to know the reason you want to do it.
It would be best leave your code as it is, and simply overwrite ‘TD’ with something else.
Neda
Neda 2018 年 1 月 28 日
編集済み: Neda 2018 年 1 月 28 日
I don't want in the loop values be random again. If by overwrite you mean B = TD, again the values in the loop created randomly. I need the size of TD be (1,I), and TD should be values within t1 and t2.

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

採用された回答

Image Analyst
Image Analyst 2018 年 1 月 28 日
randi() takes a range of integers. Since you want that range to change every column, I don't see how there is a way to do it without a for loop. However, if the (badly-named) I is less than a million, the for loop will be fast (less than a second or so)

その他の回答 (1 件)

Star Strider
Star Strider 2018 年 1 月 28 日
The code you posted does exactly what you describe.
Try this instead of the loop if you simply want something different:
TD = randi(10, 1, I);

カテゴリ

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