How to plot scatter plot with conditions?

조회 수: 17 (최근 30일)
Jayden Yeo
Jayden Yeo 2023년 2월 28일
댓글: Davide Masiello 2023년 2월 28일
Hi,
I have 2 columns of data (below table is an extract).
If the Time in row (i+1) - row (i) is less than 3, I want to plot the corresponding PW in a scatter plot. How can I do this in Matlab?
For example, the Time value in row 2 subtract the Time value in row 1 is zero, hence the PW value of 10 and 10.2 will be plotted in a scatter plot.
Thanks in advance.

채택된 답변

Davide Masiello
Davide Masiello 2023년 2월 28일
편집: Davide Masiello 2023년 2월 28일
data = readmatrix('table.xlsx');
time = data(:,1);
PW = data(:,2);
You can identify all the indexes for which the difference between two rows is less then three in the following way.
idx = abs(diff(time)) < 3;
However, idx now has length(time)-1 elements (because it perofrms subraction of i+1 and i elements one pair at a time).
You can easily fix it with
idx = [idx(1);idx];
And then plot your selected data
scatter(time(idx),PW(idx),[],PW(idx),"filled")
  댓글 수: 2
Jayden Yeo
Jayden Yeo 2023년 2월 28일
Thanks for the quick reply. It works. Using the same table, is it possible to use a different colour markers for each of the 3 blocks of data highlighted in orange in the table?
Davide Masiello
Davide Masiello 2023년 2월 28일
Hi @Jayden Yeo, I've edited my answer, now the scattered marks are colored according to the PW value.
If it helped, please consider accepting the answer. Cheers.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by