Subscripting into an empty matrix is not supported

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)".
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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 9월 22일
x = x(:);
UPDN = [x(2:end);[1;1]] >= [x(1:end-2);[0;0]];

댓글 수: 1

Tamer
Tamer 2014년 9월 24일
This answer is not working with me, it solved the problem, but I still want the If function and for statement at my program.
Do you have another suggestion please?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tamer
Tamer 2014년 9월 23일
편집: Tamer 2014년 9월 23일
Thank you Andrei,
your solution fixed my problem but my Matlab program has lots of (for & if statement). Do you have another solution for this problem ? I have to keep the if & For statement as showing at the example below.
for p=2:pp-2
if (dero(p)+1 == dero(p+1)&& dero(p)+2 == dero(p+2));
dero2(p+1)=0;
end
end
Thanks, -- Tamer

댓글 수: 3

dero2 = dero;
dero2(conv2(diff(dero(:)),[1;1])==2) = 0;
or
dero2(strfind(diff(dero(:)),[1 1])+1) = 0;
Tamer
Tamer 2014년 9월 24일
Andrei,
I have to keep the (if)statement and (for) loop at my program, because I have lots of (for) loops and (if) statement at my program. do you have another solution by keeping (if) and (for)?
Thanks for you help -- Tamer
Tamer
Tamer 2014년 9월 27일
Andrei,
This solution is not working at Matlab 2013a, do you have any other solution?
Thanks,
Tamer

댓글을 달려면 로그인하십시오.

질문:

2014년 9월 22일

댓글:

2014년 9월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by