Info
此问题已关闭。 请重新打开它进行编辑或回答。
problem with my code please !!
1 次查看(过去 30 天)
显示 更早的评论
Hi guys , How I can solve this error in my code see the attach file
the error appear in last four lines ...
8 个评论
Walter Roberson
2016-3-19
Star Strider: is it possible that you are using the R2016a pre-release rather than the full version? There were some experimental changes in R2016a pre-release that were moved again before the full version.
Star Strider
2016-3-19
Hi Walter,
I’m running the full R2016a. By mistake, I didn’t scroll all the way down, so I didn’t run the full code the first time. When I ran all of it, I got the error, and suggested linspace in the event the limits were described but the vector length was not. (We don’t know.) If it’s necessary to use the colon operator to create the vectors, and the limits are fixed, then I don’t see a solution.
We probably need to see the problem statement in order to attempt an Answer, which is the reason I didn’t.
回答(2 个)
Ced
2016-3-18
Interesting, not sure how matlab 2016 handles this. I am getting a "Matrix dimensions must agree" error, and for good cause.
In short:
You need to define n1, n2, n3 such that they all have the same length.
In detail:
in line 17: x1 has length 10
n1 = 6:15;
x1 = [ones(1, 10)]; % what you had
% x1 = 1:length(n1); % My suggestion
line 25/26: x2 has length 5
n2 = 1:5
x2 = (1/3).^n2
line 33/34: x3 has length 20
n3 = 1:20
x3 = cos (pi*n3/4)
In line 71, you try to add all three, but matlab does not know how to add three vectors of different lengths.
0 个评论
John BG
2016-3-19
subplot has 3 indices. Changing your subplot indices as follows then it doesn't return error:
n=1:20
h=3*(-1/4).^n
;subplot(4,2,1);stem(n,h)
xlabel('Sample');ylabel('Amplitude');title('h[n]');
%(b) Calculate the output of this system for following inputs;
%1. x1[n] = u[n-5] 1 ? n ? 10
n1 = 6:15;
x1 = [ones(1, 10)];
subplot(4,2,2);stem(n1, x1)
xlabel('Sample');ylabel('Amplitude');title('x1[n]');
%2. x2[n] = (1/3)^n u[n] 1 ? n ? 5
n2 = 1:5
x2 = (1/3).^n2
subplot(4,2,3);stem(n2, x2)
xlabel('Sample');ylabel('Amplitude');title('x2[n]');
%3. x3[n] = cos (pi*n/4) 1 ? n ? 20
n3 = 1:20
x3 = cos (pi*n3/4)
subplot(4,2,4);stem(n3, x3)
xlabel('Sample');ylabel('Amplitude');title('x3[n]');
%The Output
%y1
y1 = conv(x1,h);
subplot(4,2,5);stem(y1)
xlabel('Sample');ylabel('Amplitude');title('y1');
%y2
y2 = conv(x2,h);
subplot(4,2,6);stem(y2)
xlabel('Sample');ylabel('Amplitude');title('y1');
%y3
y3 = conv(x3,h);
subplot(4,2,7);stem(y3)
xlabel('Sample');ylabel('Amplitude');title('y3');
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!