clear an array

조회 수: 44 (최근 30일)
Rakshmy  C S
Rakshmy C S 2011년 12월 14일
댓글: Muntazim Abbas Hashmi 2016년 8월 26일
Hi, I want to clear the array v[] before going to the next iteration of 'j'. i.e. after the stmt arr(i,j)=min_val; /*Code begins here*/
arr=zeros(4,4);
pat='32131313';
m=8;
for i=1:4
for j=1:4
s=1;
for k=1:m-1
if str2num(pat(k))==i && str2num(pat(k+1))==j
val(s)=m-k+1;
s=s+1;
end
end
if str2num(pat(m))==i
val(s)=1;
s=s+1;
elseif str2num(pat(1))==j
val(s)=m+1;
s=s+1;
else
val(s)=m+2;
s=s+1;
end
min_val=min(val);
arr(i,j)=min_val;
end
end
  댓글 수: 1
Sean
Sean 2011년 12월 14일
I dont see an array v[] to clear in your code. Did you mean to refer to val[]? If so, why not just add 'clear val;' on the line following 'arr(i,j)=min_val;'?

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

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 14일
Instead of clearing val after the loop, initialize it before the loop
val = [];
  댓글 수: 1
Muntazim Abbas Hashmi
Muntazim Abbas Hashmi 2016년 8월 26일
I agree

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

추가 답변 (1개)

Rakshmy  C S
Rakshmy C S 2011년 12월 14일
I got the answer
clear val;

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by