Error in Build,deploy android app model using Accelerometer sensor.
古いコメントを表示
function [peaks, peakno]= Accelerometerdata(Acceleration)
z = Acceleration.Z;
smtlb = sgolayfilt(z,9,21);
peaks=findpeaks(smtlb,t,'MinPeakDistance',1);
peakno=numel(findpeaks(smtlb));
end
回答 (1 件)
Walter Roberson
2023 年 1 月 31 日
Is there a particular reason your last line is not
peakno = numel(peaks);
??
I would suggest that you pre-allocate peaks and that you pass the maximum size as NPeaks to findpeaks() . That will prevent Simulink from complaining about peaks being unknown size.
5 件のコメント
Kelvin John
2023 年 1 月 31 日
Walter Roberson
2023 年 2 月 1 日
You should expect this. findpeaks() can return a list of peaks that is anywhere between empty and half the length of the original data. Static analysis does not have any way of knowing how many peaks are going to be returned.
If you do
maxpeaks = 50;
peaks = zeros(1, maxpeaks);
coder.varsize('peaks', [1 maxpeaks]);
peaks = findpeaks(smtlb, t, 'MinPeakDistance', 1, 'NPeaks', maxpeaks);
peakno = numel(peaks);
Now Simulink can be sure of the maximum size of peaks.
Note that passing around variable-sized arrays in Simulink can be tricky.
Kelvin John
2023 年 2 月 8 日
Walter Roberson
2023 年 2 月 8 日
Suppose that you did manage to return a variable-length list of peak heights. What would you do with the variable-length list downstream ?
Kelvin John
2023 年 2 月 8 日
カテゴリ
ヘルプ センター および File Exchange で Signals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!