How to find the peak values from simulink file(.slx) in matlab coding. I'm getting pks = 0×1 empty double column vector, locs = 0×1 empty double column vector errors.

2 views (last 30 days)
The file .slx file is attatched below
  2 Comments
Mathieu NOE
Mathieu NOE on 8 Nov 2021
hello
I could not do the sim because I lack some toolboxes
can you save your simulation outputs to a mat file ?
Mathieu NOE
Mathieu NOE on 15 Nov 2021
hello
as I said before , I cannot work from your sim because i don't have the library 'powerlib'
I could only help you if you could share the results of sim, saved in a mat file
tx

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 16 Nov 2021
hello
so the issue is to plot the max of your data (once taken the absoute value of it) . In this case findpeaks is overkill, a simple max is enough to find the point and plot it
NB : the code works for a max positive or negative value
load('all_components_values_matlab.mat');
t = Inrushcurrent.Time;
Inrushcurrent = Inrushcurrent.Data ;
plot(t,Inrushcurrent);
title('Inrush current at 0 degrees switching angle')
ylabel('Inrush current [A]')
xlabel('Time [s]')
grid on
hold on
%Finding the peak (max of absolute value) values of inrush current (positive or negative)
[~,locs] = max(abs(Inrushcurrent));
t_peak = t(locs);
Inrushcurrent_peak = Inrushcurrent(locs);
plot(t_peak,Inrushcurrent_peak,'dr');
text(t_peak+0.05,Inrushcurrent_peak,['Inrush current = ' num2str(Inrushcurrent_peak) ' A']);
  3 Comments

Sign in to comment.

More Answers (1)

Mathieu NOE
Mathieu NOE on 19 Nov 2021
hello again
so this is the improved version of my code
I also rounded the peak values numbers displayed in the plot
load('all_components_values_matlab.mat');
[samples,phases] = size(Inrushcurrent);
%Finding the peak (max of absolute value) values of inrush current (positive or negative)
figure(1)
title('Inrush current at 0 degrees switching angle')
for ci = 1:phases
[~,locs] = max(abs(Inrushcurrent(:,ci)));
t_peak(ci) = t(locs);
Inrushcurrent_peak(ci) = round(Inrushcurrent(locs,ci));
subplot(phases,1,ci),plot(t,Inrushcurrent(:,ci),t_peak,Inrushcurrent_peak(ci),'dr');
text(t_peak(ci)*1.05,0.85*Inrushcurrent_peak(ci),['Inrush current = ' num2str(Inrushcurrent_peak(ci)) ' A']);
end
ylabel('Inrush current [A]')
xlabel('Time [s]')
  7 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!