How to plot scatter plot with conditions?
12 ビュー (過去 30 日間)
古いコメントを表示
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1309620/image.jpeg)
0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!