save result in while loop

I have a this code
index_A=[];
while (ibd <= max_it)
i=i+1;
index_A =[tt;index_A]
end
in i=1; index_A=[19;20].
in i=2; index_A=[14].
how I can save them all in index_A?
result should be=[19;20;14];
index_A(i) =[tt;index_A]
the above code is not working

댓글 수: 2

madhan ravi
madhan ravi 2019년 3월 18일
what's tt and why do you need a loop?
NA
NA 2019년 3월 18일
I have random variable in the loop
tto=find(mes>5);
TT=[tto;TT];
so TT is changing.
TT=[];
index_A=cell([],1);
while (ibd <= max_it)
i=i+1;
tto=find(mes>5);
TT=[tto;TT];
index_A = find( some condition);
index_A{i}= tt ;% save what you want ;
end
index_A = cell2mat(index_A) ;

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

답변 (1개)

KSSV
KSSV 2019년 3월 18일

1 개 추천

index_A=cell([],1);
while (ibd <= max_it)
i=i+1;
index_A{i}= t ;% save what you want ;
end
index_A = cell2mat(index_A) ;

댓글 수: 3

NA
NA 2019년 3월 18일
편집: NA 2019년 3월 18일
this code works for me
TT=[];
index_A=cell([],1);
while (ibd <= max_it)
i=i+1;
tto=find(mes>5);
TT=[tto;TT];
temp = find(some condition);
temp=[TT;temp];
index_A{i}= temp ;% save what you want ;
end
index_A = cell2mat(index_A) ;
KSSV
KSSV 2019년 3월 18일
index_A{i} =tt ;
KSSV
KSSV 2019년 3월 18일
We cannot help unless the whole code is shown.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

NA
2019년 3월 18일

편집:

NA
2019년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by