Store values i Matrix from a loop
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to store the interations of the the loop into a matrix with maxima and minima.
How can I do that?
%% Import data
ta0tcy100 = importdata("C:\UndrianedMon\triax_hypoplasticity-print-out\EALL_element_1.dat").data;
ta0tcy95 = importdata("C:\UndrianedMon\triax_hypoplasticityta70-print-out\EALL_element_1.dat").data;
ta0tcy90 = importdata("C:\UndrianedMon\triax_hypoplasticityta100-print-out\EALL_element_1.dat").data;
%% Finding devatoric stresses, mean pressure, shear strains and time
sig1 = [ta0tcy100(:,3) ta0tcy95(:,3) ta0tcy90(:,3)];
sig2 = [ta0tcy100(:,4) ta0tcy95(:,4) ta0tcy90(:,4)];
sig3 = [ta0tcy100(:,2) ta0tcy95(:,2) ta0tcy90(:,2)];
eps1 = [ta0tcy100(:,9) ta0tcy95(:,9) ta0tcy90(:,9)];
eps2 = [ta0tcy100(:,10) ta0tcy95(:,10) ta0tcy90(:,10)];
eps3 = [ta0tcy100(:,8) ta0tcy95(:,8) ta0tcy90(:,8)];
time = [ta0tcy100(:,1) ta0tcy95(:,1) ta0tcy90(:,1)];
q = (sig1-sig3)/2;
p = (sig1+sig3)/2;
s = eps1-eps3;
t = time;
%% Finding average and cyclic shear strains and stresses
Maxima = cell(1, size(q, 2));
MaxIdx = cell(1, size(q, 2));
Minima = cell(1, size(q, 2));
MinIdx = cell(1, size(q, 2));
for i = 1:size(q,2)
[maxima,maxIdx] = findpeaks(s(:,i));
[minima,minIdx] = findpeaks(-s(:,i));
Maxima{i} = maxima;
MaxIdx{i} = maxIdx;
Minima{i} = -minima;
MinIdx{i} = minIdx;
end
1 个评论
回答(1 个)
Joe Vinciguerra
2024-3-7
Depending on what exactly you're trying to do, put inside your for loop...
1) If you just want to store an array of i values you can add
ii{i} = i;
or
ii(i) = i;
2) If you want to store i as a vector within the same array as the other variables you could change, for example
Maxima{i} = maxima;
to be
Maxima{i,1} = maxima;
and add
Maxima{i,2} = i;
(or swap the index positions for a horizontal versus vertical array)
1 个评论
Rik
2024-3-7
Just a note: Maxima{i,2} = i; will not add a lot of value, since it can be replaced with this:
Maxima = cell(3,1);
for n=1:size(Maxima,1)
Maxima{n,1} = n;
end
Maxima(:,2) = num2cell(1:size(Maxima,1));
Maxima
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stress and Strain 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!