Obtaining max value from cyclic data
5 views (last 30 days)
Show older comments
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 Comments
Ganesh
on 17 Jan 2024
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?
Accepted Answer
Dyuman Joshi
on 17 Jan 2024
Moved: Dyuman Joshi
on 17 Jan 2024
For each cycle, finding the maximum of the temperatures corresponding to the step == 3;
%Read the data
T = readtable('Reference.xlsx')
%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]
More Answers (1)
Mathieu NOE
on 17 Jan 2024
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')
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!