How do I plot six different matrices?
Mostrar comentarios más antiguos
I have 6 different matrixes, 22x1 each one. When I plot them I get this:
plot(x1,y1,'o',x2, y2,'o', x3, y3,'o') %%Using this code
What I need to have is this:

In other words, I need to connect, for example, [x1(1) y1(1)] [x2(1) y2(1)],[x3(1) y3(1)].
I used this but it didn't work
for i=1:1 plot([x1(i) y1(i)], [x2(i) y2(i)] ,[x3(i) y3(i)])
end
Respuesta aceptada
Más respuestas (3)
Star Strider
el 6 de En. de 2019
This should get you started:
t = linspace(0, pi, 20); % Create Data
x = 3*cos(t); % Create Data
y = -3*sin(t); % Create Data
figure
plot(x, y, 'o', 'MarkerFaceColor','b')
hold on
plot([ones(size(x))-1; x], [ones(size(y))-0.5; y], '-b')
plot(0, 0.5, 'ob', 'MarkerFaceColor','b')
hold off
axis equal
The Plot —

The idea is to plot individual lines from whatever you define as the origin (here: (0,0.5)), and the individual circles. The second plot call does that, using matrix arguments that correspond to [x_origin; x_destination], and [y_origin; y_destination].
2 comentarios
Arda Nova
el 6 de En. de 2019
Star Strider
el 6 de En. de 2019
The origin appears to be at (0,0). If it is somewhere else, you can easily adapt my code to change it. (I changed your ‘x’ vector to ‘x1’ to make it compatible with the rest of the code. I also changed the comma decimal separators to period.)
Now, with your data, this code:
figure
plot([zeros(size(x1)), x1]', [zeros(size(y1)), y1]','-ok', [x1, x2]', [y1, y2]','-ok', [x2, x3]', [y2, y3]','-ok', 'MarkerFaceColor','k')
axis equal
xlim([-3.5, 3.5])
produces this plot:
%20-%202019%2001%2006.png)
Chjange the circle colors if you want to. I chose to make them black to match the plot image you posted.
Image Analyst
el 6 de En. de 2019
1 voto
What I would to is
- Take the inner most x and y vectors (let's call them x1 and y1) and fit to a circle. Use The FAQ. Now you should have the radii and the center.
- Then I would convert each of the 3 arrays to polar coordinates where the center/origin is the center of the innermost set.
- Then I would sort the points in each of the 3 sets by angle and convert back to cartesian coordinates. Now you have the points ordered from top left to bottom middle to top right.
- Then I'd have a loop where I go along the sorted x1, y1 arrays using plot() or line() to draw a line to the center point you found in setp 1.
- Then I'd have a loop over the second set of sorted x2,y2 (the middle set) where you draw a line, with plot() or line() to the corresponding index in the innermost (x1,y1) set, and the outermost (x3, y3) set. Now all lines are drawn.
Then you should be done. Note: this assumes that all vectors are the same length. You seem assured of this, but just to be robust, you should do a check first and throw an error to warn the user if they're not the same length.
I didn't use distance to closest point since some distances were quite similar and you looked like you wanted it to be ordered and not have any points skipped, so that's why I sorted and went down the sorted lists in a for loop.
Pretty easy algorithm, I think, but if you still have trouble, attach your x and y data.
1 comentario
Arda Nova
el 6 de En. de 2019
GMD Baloch
el 6 de En. de 2019
0 votos
Can you provide me the data you want to plot, so that I may understand the problem well and help you
5 comentarios
Arda Nova
el 6 de En. de 2019
Arda Nova
el 6 de En. de 2019
GMD Baloch
el 7 de En. de 2019
Sorry for being late, you can try this
clear
clc
x1=[1 1 1 1 0.999999912 0.999690873 0.998202938 0.996110802 0.992961257 0.980004982 0.924939672 0.820535897 0.602167816 0.398690056 0.203859669 -0.075955146 -0.304796417 -0.557870458 -0.864153125 -0.99993919 -0.988967944 -0.999529311];
y1=[0 -2.54e-10 -3.15E-07 -1.62E-05 -0.000419996 -0.02486278 -0.059924071 -0.088109422 -0.118439611 -0.198972951 -0.380113933 -0.571594998 -0.798369539 -0.917085732 -0.97900012 -0.997111235 -0.952417526 -0.82992804 -0.50322895 -0.011027972 0.14812969 0.030678273];
x2 = [2
2
2
2
1.999999912
1.999690873
1.998202929
1.996110712
1.992960745
1.979993679
1.924375819
1.81311973
1.510835006
0.912920593
0.344944452
-0.139948732
-0.785972062
-1.356710455
-1.804704529
-1.980245442
-1.987180774
-1.998004715];
y2=[0
-2.54E-10
-3.15E-07
-1.62E-05
-0.000419996
-0.024874491
-0.060061709
-0.08853234
-0.119452311
-0.203727586
-0.413690537
-0.693157058
-1.215890722
-1.774737732
-1.968997637
-1.995061545
-1.829041733
-1.431471605
-0.842880325
-0.208511267
0.088370616
0.085876712];
x3=[3
3
3
3
2.999999912
2.999690873
2.998202929
2.996110712
2.992960745
2.979993678
2.924375609
2.813103613
2.509294444
1.843529705
0.621048704
-0.782583788
-1.680485396
-2.277495171
-2.690548186
-2.858916151
-2.893450016
-2.924109296];
y3=[0
-2.54E-10
-3.15E-07
-1.62E-05
-0.000419996
-0.024874492
-0.060061779
-0.088532791
-0.119454264
-0.203752975
-0.414339097
-0.698834419
-1.27137721
-2.140752324
-2.93012533
-2.76123397
-2.276082999
-1.821542761
-1.306864177
-0.685939571
-0.334330296
-0.291390175];
for i=1:length(x1)/2
x_data = [x3(i) x2(i) x1(i) 0 x1(length(x1)-i+1) x2(length(x2)-i+1) x3(length(x3)-i+1)];
y_data = [y3(i) y2(i) y1(i) 0 y1(length(y1)-i+1) y2(length(y2)-i+1) y3(length(y3)-i+1)];
plot(x_data,y_data,'-o')
hold on
x_data = [];
y_data = [];
end

Arda Nova
el 7 de En. de 2019
GMD Baloch
el 7 de En. de 2019
You are welcome and if you liked my work kindly accept my answer
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
