Subscripting into an empty matrix is not supported using For Loop and if Statement
이전 댓글 표시
Hi There,
I have the following simple Matlab code, and I'm trying to implement the HDL code for it. but I got this error "Subscripting into an empty matrix is not supported" for "x(k+2)".
I have to use the (for) Loop and if statement at my program, as all my program has been created by (if) statement and (for) Loop is there anyone could help me on that?
x=amp*sin(2*f*t);
k=1;
km=31416;
UPDN=zeros(1,km,'double');
for k=1:1:km-2;
if x(k+2)>=x(k);
UPDN(k)=1;
else
UPDN(k)=0;
end
end
for k=km-1:1:km;
UPDN(k)=1;
end
답변 (2개)
Tim McBrayer
2014년 9월 30일
0 개 추천
You don't really have enough information to go on here. Some clarifying questions:
- What is the exact text of the error, and what are you doing when you receive it?
- What size is your x array?
Some observations:
- You don't need to set k = 1; this might even interfere with type analysis
- You shouldn't use a constant for km, since it appears to be required to be length(x). Use the length expression instead.
- Your UDPN array is only being assigned 0 or 1. If this is actually the only two values that it can take, you are better off (from a HDL perspective) declaring it as boolean or fixdt(0,1,0), not double.
Andrei Bobrov
2014년 9월 30일
편집: Andrei Bobrov
2014년 9월 30일
All work.
km=31416;
x = rand(km,1);
UPDN=zeros(size(x));
for k=1:km-2;
if x(k+2)>=x(k);
UPDN(k)=1;
end
end
UPDN(km-1:km)=1;
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!