how to perform plot with if?

9 ビュー (過去 30 日間)
arian hoseini
arian hoseini 2022 年 11 月 26 日
コメント済み: Dyuman Joshi 2022 年 11 月 26 日
I have two data, X and R, and I want to make it understand after the following condition is executed, for example, if the first data of X and the first data of R or the 100th data of X and the 100th data of R, if it has a value, it should perform the drawing.
for i=1:1452
if (x(i)>-20) && (x(i)<100) && (r(i)>-20) && (r(i)<100)
x(i)=x(i)
r(i)=r(i)
else
x(i)=nan
r(i)=nan
end
end
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2022 年 11 月 26 日
Store the indices which satisfy the condition, and plot the corresponding values.
%logical indexing to find the indices
idx=(x>-20&x<100)&(r>-20&r<100);
%plotting
plot(x(idx),r(idx))

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by