How do I add values into a vector

조회 수: 44 (최근 30일)
Reuben Hemmerdinger
Reuben Hemmerdinger 2021년 11월 30일
답변: Voss 2021년 11월 30일
Hi. I am creating a shot tracking program using made and missed shots. After I have found the percentage for each day someone went and shot hoops, I want to add the daily percentage into a vector. I am very new to matlab. Thank you in advance.

답변 (1개)

Voss
Voss 2021년 11월 30일
Here are four ways you can make a vector x that contains integers from 1 to 10.
x = [];
for i = 1:10
x(end+1) = i;
end
x = [];
for i = 1:10
x(i) = i;
end
x = zeros(1,10);
for i = 1:10
x(i) = i;
end
x = 1:10;
One or the other may be better for your purpose, depending on how your variables are set up before you need to build this vector and depending on whether there's any conditional logic necessary (e.g., only compute the daily average if at least 1 shot was attempted or whatever).

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by