How to correct the invalid expression error when i have the correct delimiters and multiplication operator?
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to run this code, but i am getting the invalid expression error for line 6. All parathensis are correct:
xz(t)=e^(j*pi*m(t));
xp(t)=pi*m(t);
xI(t)=cos(pi*m(t));
xQ(t)=sin(pi*m(t));
Ts=50;
t=(0:Ts:3);
m(t)=((t>=0)f(t<1)).*(-1+2*t)+((t>=1)f(t<2)).*(2-t);
plot(t,pi*m(t));q0xp(t);
plot(t,cos(pi*m(t)));qoxz(t);
plot(t,sin(pi*m(t)));qoxQ(t);
댓글 수: 2
답변 (1개)
Benjamin Kraus
2022년 2월 22일
This is an invalid MATLAB expression:
(t>=0)f(t<1)
Specifically, this is invalid:
(t>=0)f
It is unclear what you intend for MATLAB to do? Should MATLAB multiply a logical vector with the value of f? What is the value of f? If you want MATLAB to do an element-by-element multiplication of the value of (t>=0) with the value of f then you need this:
(t>=0).*f
And this may be invalid, depending on the value of f and t.
f(t<1)
In this case (t<1) will be a logical vector and f can either be a function or index. If f is a function, then you are calling that function with a logical vector. If f is a variable, then you will get an invalid index for any value that is less than 1, becase 0 is not a valid index for a MATLAB vector (which is 1-based).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!