hi, anyone knows how can I plot this function in Matlab?
thanks...

댓글 수: 1

Walter Roberson
Walter Roberson 2016년 12월 12일
Are the vertical parts intended to be sudden jumps ("the value reached 1 and jumped to 0") or are they intended to be lines?
Do you just need to plot the values, or do you need all of the intermediate values?

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

 채택된 답변

Walter Roberson
Walter Roberson 2016년 12월 12일

0 개 추천

v0 = 0; v2 = 0.2; v3 = 0.3; v7 = 0.7; v8 = 0.8; v1=1;
xr = [v0, v2*(1-eps), v2, v3*(1-eps), v3, v7*(1-eps), v7, v8*(1-eps), v8, v1];
yr = [0, 1, 0, 0, 1, -1, 0, 0, -1, 0];
x = linspace(v0, v1, 500);
y = interp1(xr, yr, x);
plot(x, y);

댓글 수: 1

Note: the assigning to variables such as v2 is there so that you can be sure that you get bitwise identical meanings of literal constants. You could also write,
xr = [0, 0.2*(1-eps), 0.2, 0.3*(1-eps), 0.3, 0.7*(1-eps), 0.7, 0.8*(1-eps), 0.8, 1];
yr = [0, 1, 0, 0, 1, -1, 0, 0, -1, 0];
x = linspace(0, 1, 500);
y = interp1(xr, yr, x);
plot(x, y);
but then you have the worry about whether the 0.2*(1-eps) as a literal constant will definitely evaluate to a different value than 0.2 as a literal constant -- because if it happens to round to the same value due to some quirk of the parser, then interp1() will complain about the values not being monotonically increasing.

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

추가 답변 (2개)

Kenny Kim
Kenny Kim 2016년 12월 12일

0 개 추천

t = linspace(0,1,10001);
x = nan(size(t));
for i =1:numel(t)
if t(i) <=0.2
x(i) = 5*t(i);
elseif t(i) >0.2 && t(i) <= 0.3
x(i) = 0;
elseif t(i) > 0.3 && t(i) <= 0.7
x(i) = 1 - 5*(t(i) - 0.3);
elseif t(i) > 0.7 && t(i) <= 0.8
x(i) = 0;
else
x(i) = -1 + 5*(t(i) - 0.8);
end
end
plot(t,x); xlabel('Time (s)'); ylabel('x(t)'); title('Giris Isareti');
ahmet cakar
ahmet cakar 2016년 12월 13일

0 개 추천

First of all, thanks for the answers these really works for me.(Btw sorry for late return) So, I need to learn just one more thing. How can I do amplitude modulation to this function. so, I need to multiply x(t) by cos2*pi*fc*t (fc=100Hz , t=as I give in figure). Thanks again..

댓글 수: 4

Kenny Kim
Kenny Kim 2016년 12월 13일
편집: Kenny Kim 2016년 12월 13일
Hopefully this is what you meant.
If you continue from where I left:
fc = 100; % cosine freq
% Next multiply by 100 hz signal
x = x.*cos(2*pi*fc*t);
plot(t,x);
you get:
If you are using Walter's method then replace x with y and t with x.
ahmet cakar
ahmet cakar 2016년 12월 13일
Yeah, I think that's what I want :) thanks so much. but I want to ask something. here: x = x. <What does this "."(dot) do? (btw sorry for my bad English :) )
Walter Roberson
Walter Roberson 2016년 12월 13일
  • is the mtimes operator, which does algebraic matrix multiplication
.* is the times operator, which does element-by-element multiplication.
ahmet cakar
ahmet cakar 2016년 12월 14일
Hmm okey. Thanks again.

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

카테고리

질문:

2016년 12월 12일

댓글:

2016년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by