Matrix dimensions must agree.

1 visualización (últimos 30 días)
Carlos Antonio Hernández Guerrero
Carlos Antonio Hernández Guerrero el 28 de Feb. de 2019
Comentada: Walter Roberson el 4 de Mzo. de 2019
hi i have this code but it doesn't work i need help. I've been trying fix it but i can't.
it says "Error using .^ Matrix dimensions must agree."
Error in tarea2i1 (line 29)
Pw=Pi.^g*z;
t=1e3:100:10e3;
syms p;
%x=-1510:1:1610;
%y=((x.^2)/(41)-1000);
%y1=y*-10;
w1=2e3;
w2=8e3;
A=10;
B=20;
g=parabola;
%g1=EDFA;
z=100e-6;
figure(3)
%plot(parabola)
parabola
axis([-200 200 0 10e3])
figure(1)
f(t)=A*sin(w1*t)+B*cos(w2*t);
Pi=f(t);
plot(Pi)
figure(2)
%pione=EDFASinglePassGain_Analytical(Pi);
%stem(pione)
Pw=Pi.^g*z;
plot(Pw)
  3 comentarios
Carlos Antonio Hernández Guerrero
Carlos Antonio Hernández Guerrero el 28 de Feb. de 2019
yes it is, is to represent an optical amplifier SOA
madhan ravi
madhan ravi el 28 de Feb. de 2019
upload it

Iniciar sesión para comentar.

Respuestas (1)

possibility
possibility el 28 de Feb. de 2019
It looks like your parabola variable is either
(1) not a vector but a matrix
(2) a vector but its size is not equal to 91 (size of Pi)
  4 comentarios
Carlos Antonio Hernández Guerrero
Carlos Antonio Hernández Guerrero el 4 de Mzo. de 2019
now it showed me this
Subscript indices must either be real positive integers or logicals.
Error in tarea2i3 (line 18)
f(t)=A*sin(w1*t)+B*cos(w2*t);
Walter Roberson
Walter Roberson el 4 de Mzo. de 2019
You are confusing indexing and formulas.
In MATLAB, when you have f(t) on the left hand side of an assignment, there are two possibilities:
  1. That you are doing indexing of the variable named f and the indices in t are all positive integers. The offsets into the index given by the values in t are the relative locations where the data will be written; Or,
  2. That t resolves to a symbolic variable (Symbolic Toolbox) and that you are defining a symbolic function. When you later reference f(something) then the symbolic function will be executed with the given argument replacing t in the formula, and returning a symbolic result. For example, syms t; g(t) = sin(t+pi/3)+t;
Your t values were originally 1000, 1100, 1200, and so on up to 10000. Those are valid positive integer indices, so your f(t)= was resulting in locations 1000, 1200, 1200, and so on in vector f being assigned to, and with the other locations in f being assigned 0. This is inefficient, and could potentially lead to trouble, but each time you referred to f later you used f(t) which indexed at the same locations and pulled the values out again, so you retrieved what you wanted, so it was just inefficient use of storage.
Now with the change that possibility has suggested, your t is not coming out as exact integers, and it is no longer valid to assign to f(t).
What you should be doing is just assigning to f not f(t) .
You should also consider using t = linspace(1e3, 10e3, length(g)) to avoid a potential off-by-one error in the length due to round off. And 1/length(g) would never have been a correct increment, but 9000/length(g) might perhaps have been a correct increment. linspace() takes the guesswork out of it.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by