plot graph according to matrix index
Afficher commentaires plus anciens
r = [cos(theta), sin(theta); -sin(theta), cos(theta)];
b = [x_mat; y_mat]
a = r*b
x_mat_new = a(1,:)
y_mat_new = a(2,:)
for the above code, I can plot a graph of y_mat_new against x_mat_new, but I cant generate a graph if I change the colon to 1.
But based on my understanding, the matrix product should contain (1,1) and (1,2) element. I wonder why a graph cannot be obtained.
Réponses (1)
Changing a colon to a 1 means providing plot with a vector for x and a scalar for y (or vice versa). When you do that, one line is created for each element of the vector, and each line has one point. You cannot see a line with one point unless it has a data marker. So either use a data marker for plots like that, or modify your plot call to provide two vectors.
theta = pi/6;
x_mat = rand(1,10);
y_mat = rand(1,10);
r = [cos(theta), sin(theta); -sin(theta), cos(theta)];
b = [x_mat; y_mat];
a = r*b;
plot(a(1,:),a(2,:)) % original
plot(a(1,1),a(2,:),'o') % replacing 1st colon with 1, and using a data marker
plot(a(1,:),a(2,1),'o') % replacing 2nd colon with 1, and using a data marker
plot(a(1,1)*ones(1,size(a,2)),a(2,:)) % plotting 2 vectors
plot(a(1,:),a(2,1)*ones(1,size(a,2))) % plotting 2 vectors
Catégories
En savoir plus sur Line Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




