MATLAB: Matrix dimensions must agree.

matrix dimensions must agree

Help me, Matlab print the next error.
Matrix dimensions must agree. Error in Grafica (line 4) Vt = (3./(n.*pi)).*(2-cos(-(pi.*n))-cos(pi.*n)).*sin(pi.*n.*t);
This is my code:
clc; clear all; close all
n = 0:1:10;
t = 0:0.01:10;
Vt = (3./(n.*pi)).*(2-cos(-(pi.*n))-cos(pi.*n)).*sin(pi.*n.*t);
plot (Vt)
end

Best Answer

Yes, they must.
However you can get round that restriction by using the meshgrid function:
n = 0:1:10;
t = 0:0.01:10;
[N,T] = meshgrid(n,t);
Vt = @(n,t) (3./(n.*pi)).*(2-cos(-(pi.*n))-cos(pi.*n)).*sin(pi.*n.*t);
plot (t, Vt(N,T))
grid on
Experiment to get the result you want.
Related Question