필터 지우기
필터 지우기

Plotting line between points

조회 수: 2 (최근 30일)
Adaptine
Adaptine 2016년 11월 18일
편집: Adaptine 2016년 11월 18일
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

답변 (2개)

Adam
Adam 2016년 11월 18일
편집: Adam 2016년 11월 18일
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!

Adaptine
Adaptine 2016년 11월 18일
편집: Adaptine 2016년 11월 18일
That's a neat way. Improved it abit:
phase = repelem(phase, 2, 1);
semilogx(phase(2:end-1,1), phase(1:end-2,2), '--r' )
But can it e improved even more? :P

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by