convert for loop's answers into a vector

7 vues (au cours des 30 derniers jours)
다영 박
다영 박 le 2 Sep 2021
Modifié(e) : 다영 박 le 2 Sep 2021
aR2=rand(1,30)
for i=1:30
maR2= mean(aR2)
end
How can i convert for loop's answers into a vector?

Réponse acceptée

KSSV
KSSV le 2 Sep 2021
mean(aR2) is a scalar value, why you want to store it into a vector?
Are you looking for saving values in a loop into a array? Then consider below example.
n = 30 ;
A = rand(1,n) ;
iwant = zeros(1,n) ;
for i = 1:n
iwant(i) = rand*A(i)
end
The above can alos be achieved without loop.
  1 commentaire
다영 박
다영 박 le 2 Sep 2021
Modifié(e) : 다영 박 le 2 Sep 2021
I know it's a scalar but, tutorial is wanted me to make it a vector.
so, thank you for the code!

Connectez-vous pour commenter.

Plus de réponses (1)

Chunru
Chunru le 2 Sep 2021
The following is not really a conversion and more a correction;
aR2=rand(1,30);
maR2= mean(aR2)
maR2 = 0.4798

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by