Error using * Inner matrix dimensions must agree.

1 vue (au cours des 30 derniers jours)
misbah 0332
misbah 0332 le 4 Mar 2015
Commenté : David Young le 4 Mar 2015
close all;
clear all;
clc;
%x(n) = u(n) – u(n – 6)
n1 = -1:1:6; %range of x-axis
x1 = [zeros(1,1), ones(1,6),zeros(1,1)]; %signal at y-axis
subplot(3,1,1); %subplot location
stem(n1,x1); %discreet plot
xlabel('time'); %labeling
ylabel('Amplitude'); %labeling
title('x(n) = u(n) – u(n – 6)'); %labeling
%h(n) = 2^n {u(n) – u(n – 3)
n2 = -1:1:3; %range of x-axis
x2 = [zeros(1,1),ones(1,3),zeros(1,1)]; %signal at y-axis
x2 = (2.^n2).*x2; %signal at y-axis
subplot(3,1,2); %subplot location
stem(n2,x2); %discreet plot
xlabel('time'); %labeling
ylabel('Amplitude'); %labeling
title('h(n) = 2^n {u(n) – u(n – 3)'); %labeling
x1k = fft(x1);
x2k = fft(x2);
y = x1k * x2k;
y2 = ifft(y);
subplot(3,1,3);
stem(y2);
  2 commentaires
David Young
David Young le 4 Mar 2015
As you can see, your code is very hard to read. You can fix this by editing it and using the "{} Code" button.
David Young
David Young le 4 Mar 2015
I think per isakson has done it for you.

Connectez-vous pour commenter.

Réponses (1)

David Young
David Young le 4 Mar 2015
It's likely that this line
y = x1k * x2k;
should be
y = x1k .* x2k;
The * operator does matrix multiplication, but .* does array multiplication which is probably what you need here.
  2 commentaires
misbah 0332
misbah 0332 le 4 Mar 2015
same error :(
David Young
David Young le 4 Mar 2015
Then I guess you need to give more information. That's the only occurrence of * in the code you have shown, so the error must be elsewhere. Please can you give the full error message, and say which line of code produces it.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by