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!