Error using plot Vectors must be the same length.
11 ビュー (過去 30 日間)
古いコメントを表示
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)")
0 件のコメント
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!