Plotting line between points
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello
I've been searching around a bit but can't find any similar problem/solution. Say I'm generating a matrix with following values:
phase =
0.0010 -90.0000
0.0457 0
0.1903 90.0000
1.9026 0
100.0000 0
What I'm looking to do is to plot a line between those points like this:
(0.0010, -90) to (0.0457, -90)
(0.0457, -90) to (0.0457, 0)
(0.0457, 0) to (0.1903, 0)
(0.1903, 0) to (0.1903, 90)
(0.1903, 90) to (1.9026, 90)
(1.9026, 90) to (1.9026, 0)
(1.9026, 0) to (100, 0)
How can I do this without too much fuzz? Basically some sort of a square wave with variable amplitude.
I got the result I wanted doing it like this, but I was wondering if there was another clever way of doing it?
j = 1; k = 2;
for i = 1:length(phase)*2-2
semilogx([phase(j,1) phase(k, 1)], [phase(k-1, 2) phase(j, 2)], '--r')
j = j + mod(i, 2); % Increment 1 when odd
k = k + ~mod(i, 2); % Increment 1 when even
end
0 Kommentare
Antworten (2)
Adam
am 18 Nov. 2016
Bearbeitet: Adam
am 18 Nov. 2016
phaseX = [phase(:,1)'; [-1 phase(2:end-1,1)' -1] ];
phaseX( phaseX == -1 ) = [];
phaseY = [phase(1:end-1,2)'; [phase(1:end-1,2)'] ];
figure; semilogx( phaseX, phaseY(:), '--r' )
does the job I think. Whether it is 'clever' or not is debateable. There's probably a neater way to put the x values together that someone can probably come up with!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!