Plotting a signal in matlab

19 ビュー (過去 30 日間)
Eleftherios Venizelos
Eleftherios Venizelos 2020 年 6 月 9 日
コメント済み: Atsushi Ueno 2020 年 6 月 12 日
Hello, i have to plot this signal:
1, -1<=t<=5
f(t)=sin(2*pi*t), 5<t<10
0, 10<t<=15
How can i plot this particular signal and how do i define it?

回答 (2 件)

Adam Danz
Adam Danz 2020 年 6 月 9 日
編集済み: Adam Danz 2020 年 6 月 9 日
This notation,
x < y < z
is interpretted by Matlab as
(x < y) < z
but since (x < y) is always true (1) or false (0), it can be reduced to
1 < z
% or
0 < z
To create a vector of values between x and z,
x : increment : z
where increment is the step size or use
linspace(x,z,n)
where n is the number of values between and including x and z.
To determine if values in y are between x and z,
x < y & y < z % when working with vectors
x < y && y < z % when working with scalar values
  18 件のコメント
Adam Danz
Adam Danz 2020 年 6 月 11 日
The function name must match the file name. Secondly, the function name 'f' is a horrible function name. Atsushi Ueno may have given that as a generic example but you should replace that name with a meaninful function name. Good function names often include a verb that describes what the function does.
writetable()
readtable()
addpath()
plot()
get()
These all contain verbs.
Atsushi Ueno
Atsushi Ueno 2020 年 6 月 12 日
I'm sorry I've suddenly gotten into this conversation and wrote unclear comment.
But now I have learned how to answer appropriately through this conversation.
Thank you so much Eleftherios Venizelos and Adam Danz.

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


Eleftherios Venizelos
Eleftherios Venizelos 2020 年 6 月 11 日
I dont thinks this is the problem.I have wrote many main programms with functions.Now it gives me this:
function:
function y = f(t) % when working with vectors t
t( t < -1) = 0; % not actually needed
t(-1 <= t & t <= 5) = 1;
t( 5 < t & t < 10) = sin(2*pi*t(t > 5 & t < 10));
t(10 <= t & t <=15) = 0; % maybe not t>10 but t>=10
t(15 < t ) = 0; % not actually needed
y = t;
end
main:
t=-1:0.01:15; % To create a vector of values between x and z,
plot(t, f(t));
error:
Undefined function 'f' for input arguments of type 'double'.
Error in askisi6m (line 2)
plot(t, f(t));
  2 件のコメント
Adam Danz
Adam Danz 2020 年 6 月 11 日
The function name must match the file name.
Secondly, the function name 'f' is a horrible function name. Atsushi Ueno may have given that as a generic example but you should replace that name with a meaninful function name. Good function names often include a verb that describes what the function does.
writetable()
readtable()
addpath()
plot()
get()
These all contain verbs.
Eleftherios Venizelos
Eleftherios Venizelos 2020 年 6 月 11 日
Ok stupid error.Now works fine.Thanks for everything!

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

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by