Effacer les filtres
Effacer les filtres

How to generate Data using for loop

1 vue (au cours des 30 derniers jours)
Med Future
Med Future le 21 Fév 2022
Modifié(e) : Stephen23 le 21 Fév 2022
I have the following code, i am entering value manually
i want to do it using for loop how can i do that and save data in 1x1000 in mat file
prfDS = [200 500 800 1000 800 900];
n_pulsesDS = [120 400 1200 1500 600 350];
prfDS(1:120) = 200
prfDS(121:520) = 500
prfDS(521:1720) = 800
prfDS(1721:3220) = 1000
prfDS(3220:3820) = 800
prfDS(3820:4720) = 900
scatter(1:length(prfDS),prfDS)
  1 commentaire
Stephen23
Stephen23 le 21 Fév 2022
Modifié(e) : Stephen23 le 21 Fév 2022
The last interval shown in your example indexing is inconsistent with the provided data:
cumsum([120,400,1200,1500,600,350])
ans = 1×6
120 520 1720 3220 3820 4170

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 21 Fév 2022
Modifié(e) : Stephen23 le 21 Fév 2022
The simple and efficient MATLAB approach would be to use REPELEM, for example:
val = [200,500,800,1000,800,900];
num = [120,400,1200,1500,600,350];
out = repelem(val,num)
out = 1×4170
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200
numel(out)
ans = 4170
  4 commentaires
Med Future
Med Future le 21 Fév 2022
@Stephen how i can generate random values above
Stephen23
Stephen23 le 21 Fév 2022
Modifié(e) : Stephen23 le 21 Fév 2022

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by