I am having issues concatenating arrays

조회 수: 4 (최근 30일)
A Poyser
A Poyser 2023년 5월 22일
댓글: A Poyser 2023년 5월 22일
I have a piece of code that I am trying to concatinate some arrays. I am being told that they are not consistent, and that vertcat has an error
% ...
N_Vv = 100;
Vv = linspace(0, 0.7, N_Vv);
cdp_initial = 0; % Initial vanishing crack density parameter
cdp_increment = 0.01; % Increment value for cdp
applied_stress = 100; % Applied stress (modify as per your requirement)
N_cycles_max = 1000; % Maximum number of cycles (modify as per your requirement)
stress_ratio = zeros(N_Vv, 1); % Preallocate stress_ratio as a vector of zeros
for k = 1:N_Vv
% Homogenised stiffness and compliance with voids and cracks
% ...
% Calculate stress intensity factor (KIc) based on Griffith's equation
KIc0 = sqrt(1E-3 * (1 - Vv(k)) / 2 * eps' * Am * C2m * Fc * Am' * eps);
% Estimate fatigue life based on crack growth rate
% ...
% Increment cdp based on applied stress and number of cycles
% ...
% Store maximum/applied stress ratio at the corresponding index
stress_ratio(k) = KIc0 / applied_stress;
% ...
end
the line that says
stress_ratio(k) = KIc0 / applied_stress;
gives the error
I have also tried
stress_ratio(k) = KIc0 / applied_stress;
which tells me that the left and right sides have a different number of elements
How can I figure out how to correct this scaling issue
Thanks in advance
  댓글 수: 1
A Poyser
A Poyser 2023년 5월 22일
Appologies I meant that I have also tried
stress_ratio = [stress_ratio; KIc0 / applied_stress];
which gives the vertcat error

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

채택된 답변

VBBV
VBBV 2023년 5월 22일
편집: VBBV 2023년 5월 22일
In the below line you have several variables, C2m, Fc, Am which may be multidimensional matrices
KIc0 = sqrt(1e-3 * (1 - Vv(k)) / 2 * eps' * Am * C2m * Fc * Am' * eps);
  댓글 수: 4
VBBV
VBBV 2023년 5월 22일
편집: VBBV 2023년 5월 22일
Ok, It seems you have preallocated stress_ratio as
stress_ratio = zeros(N_Vv, 1);
Then you need to change it as
stress_ratio = zeros(N_Vv, length(C2m),length(Am));
whichever that fits dimension. Then assign it to the variable stress_ratio as
stress_ratio(k,:,:) = KIc0 / applied_stress;
Its better not to preallocate any zeros to variable since it size of matrices change every iteration, Its better to use cell arrays instead to store multdimensional matrices as they dynamically adjust the dimensions of the matrices
% comment the below line
%stress_ratio = zeros(N_Vv, 1);
% use the below
stress_ratio{k} = KIc0 / applied_stress;
A Poyser
A Poyser 2023년 5월 22일
awesome, thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by