I would like to use the findpeaks function to calculate the peaks of the different rows of the DT matrix obtained with the for loop.
Could someone explain to me how to do it?
Thanks in advance
% Input parameters
r= 0.006; % radius[m]
k= 5e-7; % thermal diffusivity[m^2/s]
pc= 1e6; % volumetric heat capacity[J/m*3*K]
qs= 62.5; % heat input per unit of lenght per unit of time[J/m*s]
t0= [1 10 100 1000]; % heating duration[s]
Qs= qs./pc; % source strenght per unit time[m*2*K/s]
n=100;
% for loop
for i=1:length(t0)
time = logspace(0,4,n);
idH = find(time < t0(i));
idC = find(time>=t0(i));
tH = time(idH);
tC = time(idC);
t= [tH tC];
DeltaTH = (-Qs./(4.*pi.*k)).*-expint((r.^2)./(4.*k.*tH));
DeltaTC = (Qs./(4.*pi.*k)).*-(expint((r.^2)./(4.*k.*(tC-t0(i))))-expint((r.^2)./(4.*k.*tC)));
DT(i,:) = [DeltaTH DeltaTC];
end

 채택된 답변

Star Strider
Star Strider 2019년 8월 7일

1 개 추천

Since ‘DT’ appears to be two concatenated row vectors, add this line just after ‘DT’:
[pks{i},locs{i}] = findpeaks(DT(i,:));
so the loop is now:
for i=1:length(t0)
time = logspace(0,4,n);
idH = find(time < t0(i));
idC = find(time>=t0(i));
tH = time(idH);
tC = time(idC);
t= [tH tC];
DeltaTH = (-Qs./(4.*pi.*k)).*-expint((r.^2)./(4.*k.*tH));
DeltaTC = (Qs./(4.*pi.*k)).*-(expint((r.^2)./(4.*k.*(tC-t0(i))))-expint((r.^2)./(4.*k.*tC)));
DT(i,:) = [DeltaTH DeltaTC];
[pks{i},locs{i}] = findpeaks(DT(i,:));
end
Cell arrays are best for this, even though there is only one identified peak and index for each iteration. That could change if you change ‘DT’ or add name-value pairs to your findpeaks call.

댓글 수: 4

Massimiliano Gamba
Massimiliano Gamba 2019년 8월 7일
Thank you!
Star Strider
Star Strider 2019년 8월 7일
As always, my pleasure!
NIKHIL MC
NIKHIL MC 2023년 3월 15일
can we convert the cell array into matrix?? i have a cell array with each column havig different number of elements
Star Strider
Star Strider 2023년 3월 15일
@NIKHIL MC — Unless all the cell array contents are of equal size in each cell, it is not possible to concatenate them into a matrix.

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

추가 답변 (0개)

카테고리

제품

릴리스

R2017b

질문:

2019년 8월 7일

댓글:

2023년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by