필터 지우기
필터 지우기

help with preallocating matrix ?

조회 수: 1 (최근 30일)
Rahim Rahim
Rahim Rahim 2021년 2월 7일
댓글: Rahim Rahim 2021년 2월 7일
I want to preallocate a matrix a dynamic matrix Archive[M,6], The size of our matrix limited by 200. At beggening M=1 then add elements to Archive by using the following function:
function Add ( Archive, Solution)
while( size(Archive,1) <= 200 )
Archive=[Archive;Solution]
end
end
where solution is Solution[1,6].
How preallocate the Archive matrix ?

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 2월 7일
If it is are fixed,can consider the extra zeros (If generated data are not sufficients to allocate all)
Archive=zeros(1,200);
Without knowing the size of the data? you may do following way
Archive=[];
Still it not perfect as preallocate with specific size. More, check with the Elapsed time, to see the time difference of execution.
  댓글 수: 1
Rahim Rahim
Rahim Rahim 2021년 2월 7일
@KALYAN ACHARJYA thank you for answer, but I won't zeros
Are there another methods ? because I wille added [0,0,0,0,0,0,,0] as a soulution so I dont want to use this method.

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

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by