필터 지우기
필터 지우기

Continuous execution of vertical line for set of data

조회 수: 3 (최근 30일)
Sam
Sam 2021년 3월 12일
답변: Steven Lord 2021년 3월 12일
I'm new to Matlab
I want to plot a vertical line at specific values which I have stored in a variable, "HR"
For some data sets, there are several values within the variable and it would take a lot of time to plot a vertical line at each value.
Can someone help me write a code that continues to execute plotting this vertical line through the entire data set?
Example:
In the variable "HR" I have stored all of the values below. I want to plot a vertical line at each of these values. How would I go about writing a code or iterative loop to do this until it has plotted lines at each of these points and finished the data set?
0.340000000000000
0.980000000000000
4.65900000000000
5.24100000000000
38.8100000000000
39.4390000000000
239.070000000000
302.428000000000
309.415000000000
309.994000000000
312.011000000000
312.596000000000
313.162000000000
528.814000000000
926.693000000000
932.091000000000
935.019000000000
1033.03500000000
1055.55600000000
1211.96700000000
1422.35500000000
1462.23100000000
1468.41100000000
1468.99900000000
1469.61400000000
1472.49600000000
1473.09200000000
1913.67000000000
1933.99300000000
1934.57900000000
1935.12900000000
2000.45700000000
2004.35200000000
2004.93800000000
2304.14700000000
2304.73300000000
2556.99300000000
2835.84100000000
2840.34700000000
2847.08800000000

채택된 답변

ANKUR KUMAR
ANKUR KUMAR 2021년 3월 12일
"I want to plot a vertical line at each of these values. ". The array you provided is 1D array. You will get 1 line plot out of these array.
A=[0.340000000000000
0.980000000000000
4.65900000000000
5.24100000000000
38.8100000000000
39.4390000000000]
plot(A)
Are you trying to plot multiple line in the plot out of this data?
What is the dimension size of the array?
  댓글 수: 5
ANKUR KUMAR
ANKUR KUMAR 2021년 3월 12일
편집: ANKUR KUMAR 2021년 3월 12일
Hope this helps.
load('Sample.mat')
yy=data(:,2);
vert_lines=elevatedHR(:,2);
xx=1:length(yy);
plot(xx,yy)
hold on
for kk=1:length(vert_lines)
index=find(yy==vert_lines(kk));
for indices=1:length(index)
plot(ones(1,2)*xx(index(indices)),[50 110],'r-')
end
end
Sam
Sam 2021년 3월 12일
Thank you so much Ankur. I appreciate your help. I'll try this.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2021년 3월 12일
It's not clear to me exactly what type of graphic you're trying to plot, but I think the stem and xline functions may be of use to you. Alternately, open the Plots tab on the Toolstrip. Click the small downward-pointing triangle in the Plots section of that tab and look for a thumbnail that appears similar to the type of plot you want to create. From there you can determine the specific plotting function used to create that type of plot (its name is below the thumbnail) and read its doc page to learn how to use it. You can even create the plot from the thumbnail if you have your data selected in the Workspace window.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by