필터 지우기
필터 지우기

The size of the indicated variable

조회 수: 2 (최근 30일)
Yigit
Yigit 2011년 11월 20일
Hi,
When I run the following code ;
i=0;
t0 = clock;
while etime(clock, t0) < 10
disp(clock);
pwm(i)=0;
i = i +1;
tic
while toc<secs
end
pwm(i)=1;
i = i +1;
tic
while toc<secs
end
end
I get the following warning ;
The size of the indicated variable or array appears to be changing with each loop iteration. Commonly, this message appears because an array is growing by assignment or concatenation.
and application hangs even if it's a very simple algorithm.
Any ideas ?
  댓글 수: 1
Yigit
Yigit 2011년 11월 20일
forgot to mention ; variable "secs" is defined in the code, didn't post those parts not to cause pollution.

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

답변 (3개)

Image Analyst
Image Analyst 2011년 11월 20일
I don't know how big pwm might get. Maybe run it once to see. Let's say that it ends up being 100000 elements long. Then, before your while loop, you simply preallocate:
pwm = zeros(1, 100000);
  댓글 수: 3
Image Analyst
Image Analyst 2011년 11월 21일
I can't run your code because secs is undefined. What value are you using for it?
Yigit
Yigit 2011년 11월 22일
secs change between 0.01 ~ 0.002

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


Kostas
Kostas 2011년 11월 20일
Is there any chance the variable secs to have such a little value that it is always litter than "toc"? In such a case your code goes into an infinite loop which cause it to hang.
  댓글 수: 1
Yigit
Yigit 2011년 11월 20일
secs is between 0.02 ~ 0.06, can this be causing ?

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


Jan
Jan 2011년 11월 21일
The code fails, because you try to access "pwm(i)" for i=0, but the index must be >= 1. When I start with "i=1;" the code runs successfully on my computer.
Where does the program fail on your computer? You can eitehr use the debugger or insert some disp command to check this.
I would avoid "tic; while toc<secs, end". A pause command would be smarter.
  댓글 수: 3
Jan
Jan 2011년 11월 22일
@Yigit: This is exactly the task of PAUSE.
Please provide the information I've asked for: *Where* does the program fail? It runs without problems on my machine...
Yigit
Yigit 2011년 11월 22일
problem is when I plot(i,pwm(i)) plot only shows some of the signal, not the whole

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by