How to connect lines of a scatter plot?

조회 수: 1 (최근 30일)
Samantha Horton
Samantha Horton 2018년 9월 12일
답변: dpb 2018년 9월 12일
Hello, I am trying to connect points of a graph showing the average size of a QRS complex in a rat EKG. I have two sets of data, one called normal, one called psutre. Both sets of data have some 0 components, which I have set to NaN. When I plot this with a line plot, there are blank spaces. I want to connect the data points excluding NaN without changing the size of the array. Here is what I have:
load('rat data.txt');
normal=rat_data(:,1);
psutre=rat_data(:,2);
normal(normal==0)=NaN;
%idx=~any(isnan(normal),1);
len=1:length(normal);
figure
scatter(len,normal,'m')
hold
psutre(psutre==0)=NaN;
scatter(len,psutre,'g')
Let me know how to do this please!

답변 (1개)

dpb
dpb 2018년 9월 12일
Well, the simple way is to do the plot of the data without the NaN elements; the builtin behavior is to ignore NaN and that's not changeable.
Try
...
normal(normal==0)=NaN;
idx=isfinite(normal);
len=1:length(normal);
figure
hLN=plot(len(idx),normal(idx),'m-o');
hold on
psutre(psutre==0)=NaN;
idx=isfinite(psutre);
hLP=line(len(idx),psutre(idx),'g-o')
This doesn't change the basic data arrays but only plots those that aren't NaN and won't have any breaks in the lines.
Use the line handles to modify the line properties to suit visual effect desired.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by