필터 지우기
필터 지우기

Preallocating an array or a vector in matlab before a for loop

조회 수: 4 (최근 30일)
A Poyser
A Poyser 2023년 2월 15일
댓글: A Poyser 2023년 2월 15일
I have several variables that I want to preallocate in my code before my for loop. I was hoping someone could show me the correct way to write this preaalocation. Currently it looks like this but it is giving me errors
k = 1:24;
sigma_infty = zeros(length(:,k));
eps_infty = zeros(length(:,k));
for k = k
%
sigma_infty(:,k) = [10*k 0 0 0 0 0]';
%
eps_infty(:,k) = S2*sigma_infty(:,k);
end
I keep getting told that I length and/or zeros is an unregognised function and I am unsure how to write the corrct preallocation.
Could someone please clarify how to correctly allocate these variable for me?
Thanks
Alex

채택된 답변

KSSV
KSSV 2023년 2월 15일
N = 24 ;
sigma_infty = zeros(6,N);
eps_infty = zeros(6,N);
for k = 1:N
%
sigma_infty(:,k) = [10*k 0 0 0 0 0]';
%
eps_infty(:,k) = S2*sigma_infty(:,k);
end

추가 답변 (1개)

KSSV
KSSV 2023년 2월 15일
Thanks is accepting and/or voting the answer. :)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by