Obtaining max value from cyclic data

5 次查看(过去 30 天)
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

更多回答(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.

请先登录,再进行评论。

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by