Obtaining max value from cyclic data

조회 수: 12 (최근 30일)
Goutham
Goutham 2024년 1월 17일
댓글: Dyuman Joshi 2024년 1월 17일
Hello, I need to obtain the max value of temperature from a cyclic (100 cycles) data. I have tried the following method:
% Start of code
temp_max(:,1) = GetMaxValue(temp,step,3)
function [out] = GetMaxValue(in,step,step_1)
k = 1;
for i = 2: length(temp)
if step(i) == step_1
out(k) = max(in(i))
k = k + 1;
end
end
end
% end of code
temp is the variable with temperature values and step is the variable of the step numbers. With this code, I am only getting all the values of step 3 as it has nothing to compare the max value against.
Kindly find attached for the excel file with the data. I would request you to help me solve the problem.
Thanks,
Goutham
  댓글 수: 2
Ganesh
Ganesh 2024년 1월 17일
Do you intend to obtain the maximum temperature from all the data, i.e. the max value of the third column? Or do you intend to obtain the maximum temperature for a particular value of step?
Goutham
Goutham 2024년 1월 17일
Hello Ganesh,
The attached file consists of 100 cycles worth of test data. I am interested in obtaining the maximum value of temperature (3rd column) at each of those 100 cycles when the step is 3.
Thanks

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

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 1월 17일
이동: Dyuman Joshi 2024년 1월 17일
For each cycle, finding the maximum of the temperatures corresponding to the step == 3;
%Read the data
T = readtable('Reference.xlsx')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
T = 296017×3 table
step CycleNumber temp ____ ___________ ______ 0 0 23.941 1 0 24.17 1 0 24.17 1 0 24.17 1 0 24.146 1 0 24.146 1 0 24.146 1 0 24.146 1 0 24.146 1 0 24.146 1 0 24.146 1 0 24.146 1 0 24.146 1 0 24.13 1 0 24.185 1 0 24.185
%Values that satisfy the condition
idx = T.step == 3;
%Finding groups accordingly
[grps, cycnum] = findgroups(T.CycleNumber(idx));
%Compute maximum temperature for each group
Temp_max = accumarray(grps, T.temp(idx), [], @max);
%Cycle number and corresponding Max temperature for step value of 3
out = [cycnum Temp_max]
out = 100×2
1.0000 28.9651 2.0000 28.9178 3.0000 28.7285 4.0000 28.7758 5.0000 28.7522 6.0000 28.8626 7.0000 28.8626 8.0000 28.8941 9.0000 29.0598 10.0000 28.8784
  댓글 수: 2
Goutham
Goutham 2024년 1월 17일
Thank you for response. It works perfectly.
Dyuman Joshi
Dyuman Joshi 2024년 1월 17일
You're welcome!

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

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2024년 1월 17일
hello
I don't understand your logic ... why do we need to make comparisons with anotehr result ( With this code, I am only getting all the values of step 3 as it has nothing to compare the max value against. )
here's a simple code that will generate two plots
  • first one is simply to display all temp curves (overlaid) for all cycles
  • second one will display the max temp of each cycle vs cycle number
hope it helps
data = readmatrix('Reference.xlsx'); % step / Cycle Number / temp
Cycle_Number = data(:,2);
temp = data(:,3);
CN = unique(Cycle_Number); % get unique values of cycles
% overlay plot temp (for all cycles)
figure
hold on
for k = 1:numel(CN)
ii = Cycle_Number==CN(k); % select data for cycle number = k
max_temp(k) = max(temp(ii)); % store max temp of k th cycle
plot(temp(ii))
end
% plot max_temp vs cycle number
figure
plot(CN,max_temp)
title('Max Temperature ')
xlabel('Cycle#')
ylabel('Temp')
  댓글 수: 1
Goutham
Goutham 2024년 1월 17일
Sorry for not making it clear. But I have got the solution from other colleagues. Thanks for your response.

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by