plot3 is showing axes but not vectors

I'm trying to make a script to rotate a vector around another vector and the vectors I'm trying to plot aren't showing up...
% Script to rotate a vector
close all;
clear;
vector_a = [input("Enter an x value for the vector a"), input("Enter a y value for the vector a"), input("Enter a z value for the vector a")];
theta = input("Enter a value for the rotation angle");
vector_e = [input("Enter an x value that makes vector e orthogonal to a, for the vector e"), input("Enter a y value that makes vector e orthogonal to a, for the vector e"), input("Enter a z value that makes vector e orthogonal to a, for the vector e")];
magnitude_e = sqrt(((vector_e[1]).^2)+((vector_e[2]).^2)+((vector_e[3]).^2))
norm_vec_e = [(vector_e[1])/magnitude_e, (vector_e[2])/magnitude_e, (vector_e[3])/magnitude_e]
if dot(norm_vec_e, vector_a) ~= 0
disp("There was an error as the input vectors a and e are not orthogonal");
quit;
else
vector_a_prime = vector_a*cos(theta) + cross(norm_vec_e, vector_a)*sin(theta)
end
matrix_of_vectors = [vector_a, norm_vec_e, vector_a_prime];
plotv(matrix_of_vectors, "-"); legend("Vector A", "Unit Vector E", "Vector A Prime"); grid on;

Answers (1)

First of all use these parenthesis to access an element:
vector_e(1)
MATLAB is MATrix LABoratory. Take an advantage of it
% norm_vec_e = [(vector_e[1])/magnitude_e, (vector_e[2])/magnitude_e, (vector_e[3])/magnitude_e]
norm_vec_e = vector_e/magnitude;
You can enter all elements of an array at once:
a = input('Enter vector e: ');
%%
Enter vector e: [1 2 0.2]
a =
1.0000 2.0000 0.2000
To plot all vector:
matrix_of_vectors = [vector_a; norm_vec_e; vector_a_prime]; % concantenate vertically
v0 = zeros(3,1);
% plot3(x,y,z)
plot3([v0 matrix_of_vectors(:,1)]',[v0 matrix_of_vectors(:,2)]',[v0 matrix_of_vectors(:,3)]','.-r')
% or quiver3
% hold on
% quiver(0,0,0,matrix_of_vector(:,1),matrix_of_vector(:,2),matrix_of_vector(:,3))
% hold off

Products

Release

R2019a

Asked:

on 4 Oct 2019

Answered:

on 4 Oct 2019

Community Treasure Hunt

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

Start Hunting!