Why am I receiving a "Too many output arguments" error on this particular code?
3 ビュー (過去 30 日間)
古いコメントを表示
In the following code, I am just trying to solve for the PSD of each row in the Spec.mat file, which is just a 8x512 double array. I am getting the error on line 5, and I've spent so much time on this I'm just not seeng the solution
% Load data from Spec.mat file
load('Spec.mat');
% Number of rows (process realizations)
num_rows = size(Spec, 1); <-----------------------Error here
% Number of samples per row
num_samples = size(Spec, 2);
% Calculate the power spectral density (PSD) for each row
psd_rows = zeros(num_rows, num_samples);
for i = 1:num_rows
psd_rows(i, :) = (abs(fftshift(fft(Spec(i, :)))).^2) / num_samples;
end
% Average the PSDs of all rows
psd_average = mean(psd_rows, 1);
% Sampling frequency (assuming 40 kHz)
Fs = 40e3;
% Frequency resolution
df = Fs / num_samples;
% Frequency axis
f_axis = (-num_samples/2 : num_samples/2 - 1) * df;
% Plot individual and composite PSDs
figure;
hold on;
for i = 1:num_rows
plot(f_axis, fftshift(psd_rows(i, :)));
end
plot(f_axis, fftshift(psd_average), 'k', 'LineWidth', 2);
xlabel('Frequency (Hz)');
ylabel('Power/Frequency');
title('Power Spectral Density (PSD)');
legend('Individual PSDs', 'Composite PSD');
1 件のコメント
Walter Roberson
2024 年 4 月 22 日
% Load data from Spec.mat file
Data = load('Spec.mat');
Spec = Data.Spec;
採用された回答
VBBV
2024 年 4 月 22 日
編集済み: VBBV
2024 年 4 月 22 日
Load the data and assign to a variable. When you load a MAT file using load function, it returns a struct with different data variables (with names) and the data inside the structure can be accessed as below
Data = load('Spec.mat');
% Number of rows (process realizations)
num_rows = size(Data.variableName, 1); <-----------------------Error here
% Number of samples per row
num_samples = size(Data.variableName, 2);
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Parametric Spectral Estimation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!