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 次查看(过去 30 天)
The file .slx file is attatched below
  2 个评论
Mathieu NOE
Mathieu NOE 2021-11-15
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

请先登录,再进行评论。

采纳的回答

Mathieu NOE
Mathieu NOE 2021-11-16
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 个评论

请先登录,再进行评论。

更多回答(1 个)

Mathieu NOE
Mathieu NOE 2021-11-19
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 个评论

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by