Matrix dimensions must agree.
이전 댓글 표시
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
madhan ravi
2019년 2월 28일
parabola??
Carlos Antonio Hernández Guerrero
2019년 2월 28일
madhan ravi
2019년 2월 28일
upload it
답변 (1개)
possibility
2019년 2월 28일
0 개 추천
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
Carlos Antonio Hernández Guerrero
2019년 2월 28일
possibility
2019년 3월 3일
편집: possibility
2019년 3월 3일
Define
g=parabola;
in the first line. And then change
t=1e3:1/length(g):10e3;
You should be fine.
Carlos Antonio Hernández Guerrero
2019년 3월 4일
Walter Roberson
2019년 3월 4일
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:
- 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,
- 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.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!