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.
1 次查看(过去 30 天)
显示 更早的评论
The file .slx file is attatched below
2 个评论
Mathieu NOE
2021-11-8
hello
I could not do the sim because I lack some toolboxes
can you save your simulation outputs to a mat file ?
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
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/801894/image.png)
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 个评论
Mathieu NOE
2021-11-19
hello
sorry but again the slx file will not help me
can your share again the data as at file ?
tx
Mathieu NOE
2021-11-19
sorry there was a typo in my last answer
can you share again the data as mat file ?
更多回答(1 个)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806544/image.png)
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]')
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!