I am trying to figure out how to plot my data.

1 回表示 (過去 30 日間)
Marshall Harkrider
Marshall Harkrider 2022 年 5 月 25 日
編集済み: Voss 2022 年 5 月 25 日
Data101 = linspace(0,10,500);
red_line = sin(2*pi*Data101)*1.5;
for i = 1:length(Data101)
if red_line(i) >= 0.95 && red_line(i-1) <=0.95
holdval(i) = 1;
else
holdval(i) = 0;
end
end
This is my current script. It contains my Data, named Data101, which is a 1x500 double. I want to figure out how to put this data on a figure now that I have the script I want? Any help is greatly appreciated. I am very new to this software so any tips would be appreciated too.

採用された回答

Chunru
Chunru 2022 年 5 月 25 日
Data101 = linspace(0,10,500);
red_line = sin(2*pi*Data101)*1.5;
for i = 1:length(Data101)
if red_line(i) >= 0.95 && red_line(i-1) <=0.95
holdval(i) = 1;
else
holdval(i) = 0;
end
end
figure;
plot(Data101, red_line, 'r');
hold on
stem(Data101, holdval, 'g.')
  1 件のコメント
Voss
Voss 2022 年 5 月 25 日
編集済み: Voss 2022 年 5 月 25 日
@Marshall Harkrider: Be careful with that red_line(i-1), because if it is executed with i==1, it will give you an error. That doesn't happen with this data because the && short-circuits before red_line(i-1) is executed with i==1, since red_line(1) is not >= 0.95.
But if you happened to have different data, where red_line(1) is >= 0.95, you'd have a problem:
Data101 = linspace(0,10,500);
red_line = sin(2*pi*Data101+pi/2)*1.5;
red_line(1)
ans = 1.5000
for i = 1:length(Data101)
if red_line(i) >= 0.95 && red_line(i-1) <=0.95 % error here, trying to access red_line(0)
holdval(i) = 1;
else
holdval(i) = 0;
end
end
Array indices must be positive integers or logical values.

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

その他の回答 (1 件)

the cyclist
the cyclist 2022 年 5 月 25 日
You don't say what kind of figure you want. I suggest you look at the MATLAB Plot Gallery. If you see something like what you want, you can copy code from there.

カテゴリ

Help Center および File ExchangeGraphics Object Identification についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by