aR2=rand(1,30)
for i=1:30
maR2= mean(aR2)
end
How can i convert for loop's answers into a vector?

 채택된 답변

KSSV
KSSV 2021년 9월 2일

0 개 추천

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

다영 박
다영 박 2021년 9월 2일
편집: 다영 박 2021년 9월 2일
I know it's a scalar but, tutorial is wanted me to make it a vector.
so, thank you for the code!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 9월 2일

편집:

2021년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by