Error using plot Vectors must be the same length.

조회 수: 8 (최근 30일)
Adam Makin
Adam Makin 2018년 1월 20일
댓글: Walter Roberson 2018년 1월 20일
I got the error plotting vectors must be the same length and I'm not sure why. I'm trying to plot the function v against time. In the code I've assigned values to v based on certain inequalities being met.help would be appreciated
function v=pwm(t,T,d)
d = 0.1;
T= 0.2;
t=linspace(0,2,100);
k = mod(T,t);
v(k*T<=t<k+d) = 1;
v(((k + d)*T) <= t < (k + 1)*T) = 0;
plot(t,v)
xlabel("Time(s)");
ylabel("Voltage(V)")

답변 (1개)

Walter Roberson
Walter Roberson 2018년 1월 20일
MATLAB does not have range test operations with the syntax
lower <= variable < upper
You need to break those up as two tests joined by &
A <= t & t < B
  댓글 수: 2
Adam Makin
Adam Makin 2018년 1월 20일
hi thanks for thelp. Did this and my equalities look like this:
v(k*T<=t & t < (k+d)) = 1;
v((k + d)*T <= t & t < (k + 1)*T) = 0;
However I'm still receiving the same error as before.
Walter Roberson
Walter Roberson 2018년 1월 20일
You have not specified the value v should have for locations where neither mask is true.
I suggest that you start with
v = nan(size(t)) ;

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

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by