plot graph according to matrix index
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Voss
am 10 Mär. 2025
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!