If loop matrix creation

1 次查看(过去 30 天)
Justin Manterrnacch
编辑: 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