If loop matrix creation

조회 수: 1 (최근 30일)
Justin Manterrnacch
Justin Manterrnacch 2021년 10월 8일
편집: DGM 2021년 10월 8일
theta=[0,45,90];
F=450;
for i=0:length(theta)
vector=F.*[cosd(theta),sind(theta),0];
end
Want the matricies for vector that is created to be seperate. When it currently runs, all values are in the same matrix.

답변 (1개)

DGM
DGM 2021년 10월 8일
편집: DGM 2021년 10월 8일
"Want the matricies for vector that is created to be seperate."
What exactly does that mean? I'm assuming "matrices" means "vector", but that's still ambiguous. You want the outputs to be separate, but how exactly?
theta = [0,45,90];
F = 450;
% one row for each theta
matrix = F.*[cosd(theta.') sind(theta.') [0; 0; 0]]
matrix = 3×3
450.0000 0 0 318.1981 318.1981 0 0 450.0000 0
% one row for each axis
matrix = F.*[cosd(theta); sind(theta); [0 0 0]]
matrix = 3×3
450.0000 318.1981 0 0 318.1981 450.0000 0 0 0
That gives the result as a matrix. You can index within the matrix to find the vectors you want. If you want three separate vector variables, then I have no idea why you were trying to vectorize it in the first place.
If none of this is what you want, you'll have to clarify your description of how you want the output to be arranged.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by