How to generate data using for loop and save in rows in MATLAB

Hello every one i hope you are doing well.
I have the following code which generate data.
i want it to run for 100 times and saves results in rows
like loop is 100 and output should be 100 rows
Repeat=randi([1 1000], 1, 5);
prf=randi([1 1000], 1,5);
DS =repelem(prf,Repeat);
scatter(1:length(DS(1,:)),DS(1,:))

回答 (1 件)

Davide Masiello
Davide Masiello 2022 年 3 月 4 日
編集済み: Davide Masiello 2022 年 3 月 4 日

0 投票

Something like this?
clear,clc
Repeat=randi([1 1000], 1, 10);
for i=1:200
prf=randi([1 1000], 1,10);
DS(i,:) =repelem(prf,Repeat);
plot(1:size(DS,2),DS(i,:))
hold on
end

8 件のコメント

Med Future
Med Future 2022 年 3 月 4 日
i do that but it not working
for i=1:200
Repeat=randi([1 1000], 1, 10);
prf=randi([1 1000], 1,10);
DS(i,:) =repelem(prf,Repeat);
scatter(1:length(DS(1,:)),DS(1,:))
end
Davide Masiello
Davide Masiello 2022 年 3 月 4 日
編集済み: Davide Masiello 2022 年 3 月 4 日
The problem is that Repeat is generated by a randi function, which means that the size of
repelem(prf,Repeat)
changes at every iteration of the loop.
In order to fill up DS, you must have the same row length at each iteration.
Med Future
Med Future 2022 年 3 月 4 日
@Davide Masiello then how can i do that?
Davide Masiello
Davide Masiello 2022 年 3 月 4 日
It depends on what you need.
Why do you use repelem?
Med Future
Med Future 2022 年 3 月 4 日
@Davide Masiello repelem is used to generate specific shape
Davide Masiello
Davide Masiello 2022 年 3 月 4 日
Shape of what? And how can it be specific if you use a random function?
I would suggest you take some time to edit your questoin and make it as clear as possible, providing the best code you could write.
Only then it will be possible to give you some help.
Med Future
Med Future 2022 年 3 月 4 日
@Davide Masiello shape of wave
Davide Masiello
Davide Masiello 2022 年 3 月 4 日
編集済み: Davide Masiello 2022 年 3 月 4 日
Still not sure what you mean, but I have edited my answer, please see if it sorts out your problem.

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

カテゴリ

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

製品

リリース

R2021b

質問済み:

2022 年 3 月 4 日

編集済み:

2022 年 3 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by