フィルターのクリア

Error with Vector Length

51 ビュー (過去 30 日間)
David Irza
David Irza 2024 年 5 月 24 日 1:41
コメント済み: Steven Lord 2024 年 5 月 24 日 14:57
Hi All,
Trying to get this code to work for a school lab assignment. I keep getting a vector length error, but my classmates are not having the same problem. Not sure what is the difference between my system and theirs. We are all running MATLAB R2022b. Could someone please point me in the right direction and explain why this isn't working?
Thanks!
Code:
clear;
close all;
t0=0;
t1=-10;
t2=20;
[x,t]=step(t0,t1,t2)
x = 101x1
0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
t = []
figure
plot(t,x,'r','linewidth,2');
Error using plot
Specify the coordinates as vectors or matrices of the same size, or as a vector and a matrix that share the same length in at least one dimension.
xlabel('Time (s)');
ylabel('Signal Amplitude');
Error Message:

回答 (1 件)

Matt J
Matt J 2024 年 5 月 24 日 1:58
The code you've shown produces empty t:
t0=0;
t1=-10;
t2=20;
[x,t]=step(t0,t1,t2);
x=x',t
x = 1x101
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
t = []
  4 件のコメント
Matt J
Matt J 2024 年 5 月 24 日 14:25
Perhaps your professor has provided his own implementation of step(), which you are missing. You can investigate this by going to one of your classmates for whom the code is working and have them execute,
which -all step
Steven Lord
Steven Lord 2024 年 5 月 24 日 14:57
Without seeing the code for the step function your professor gave you, it's going to be nearly or completely impossible for us to offer any but general guidance. I'd say you should:
  1. Check that you're using the step function that your professor gave you, that it hasn't been accidentally modified (an extra digit introduced somewhere via a typo could easily change what it returns.)
  2. That you haven't shadowed the functions included in MATLAB that the step function uses. You could cause a lot of havoc (in user-written code) if you redefined the pi function to return 4, for example. [Built-in functions generally get the value the built-in pi function returns a different way.] See below.
  3. If after debugging you still can't determine why the code isn't behaving as expected, ask the author and/or the maintainer (the professor or one of the teaching assistants.)
The debugging tools in MATLAB may help you determine why the second output of the step function is empty when you didn't expect it to be.
Example: can you change pi?
mydeg2rad1 = @(deg) pi*deg/180;
mydeg2rad2 = @(deg) builtin('pi')*deg/180;
mydeg2rad1(90)
ans = 2
mydeg2rad2(90)
ans = 1.5708
function p = pi
p = 4;
end

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by