Subscripting into an empty matrix is not supported using For Loop and if Statement
Ältere Kommentare anzeigen
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
Antworten (2)
Tim McBrayer
am 30 Sep. 2014
0 Stimmen
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
am 30 Sep. 2014
Bearbeitet: Andrei Bobrov
am 30 Sep. 2014
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;
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!