Error in my code
In my code below i get error at here:
% Calculate features
[~, I] = max(P_k);
%peak power frequency
peakPowerFreq(k) = fvec(I);
It says: Unable to perform assignment because the left and right sides have a different number of elements.
Error in untitled5 (line 24)
peakPowerFreq(k) = fvec(I);
Because of this error, i cant extract frequency features of bearing signals.
Can you help please.
url = 'https://www.mathworks.com/supportfiles/predmaint/condition-monitoring-and-prognostics-using-vibration-signals/pdmBearingConditionMonitoringData.mat';
websave('pdmBearingConditionMonitoringData.mat',url);
load pdmBearingConditionMonitoringData.mat
% Define the number of data points to be processed.
numSamples = length(data);
% Define sampling frequency.
fs = 20E3; % unit: Hz
peakPowerFreq = zeros(numSamples, 1);
for k = 1:numSamples
%Get most up-to-date data.
curData = data{k};
% Calculate spectrogram.
[~, fvec, ~, P_k] = spectrogram(curData, 500, 450, 512, fs);
% Calculate features
[~, I] = max(P_k);
%peak power frequency
peakPowerFreq(k) = fvec(I);
end
% Plot Peak Power Frequency
figure;
plot(expTime, peakPowerFreq);
xlabel('Time (min)');
ylabel('Peak Power Frequency (Hz)');
title('Peak Power Frequency vs. Time');
grid on;
2 Comments
Answers (1)
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!