what is wrong in this code?

1 次查看(过去 30 天)
load('matlab.mat', 'voltage');
level = 6;
wavelets = {'haar','db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10','sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9',
'sym10','coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'bior1.1', 'bior1.3', 'bior1.5', 'bior2.2', 'bior2.4', 'bior2.6', 'bior2.8', 'bior3.1', 'bior3.3', 'bior3.5',
'bior3.7', 'bior3.9', 'bior4.4', 'bior5.5', 'bior6.8','rbior1.1', 'rbior1.3', 'rbior1.5', 'rbior2.2', 'rbior2.4', 'rbior2.6', 'rbior2.8', 'rbior3.1', 'rbior3.3', 'rbior3.5', 'rbior3.7', 'rbior3.9', 'rbior4.4', 'rbior5.5', 'rbior6.8', 'dmey', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22'};
SD = zeros(1, length(wavelets)); % preallocate SD vector with zeros
for i = 1:length(wavelets)
% Perform wavelet decomposition
[c,l] = wavedec(voltage, level, wavelets{i});
% Extract detail coefficients from level 6
details = detcoef(c,l,6);
% Calculate standard deviation of detail coefficients
SD(i) = std(details);
end
% Display the results
disp(SD)
Error
Dimensions of matrices being concatenated are not consistent.
Dimensions of matrices being concatenated are not consistent.
  3 个评论
Star Strider
Star Strider 2023-3-12
I do not see that you are concatenating any matrices in the posted code.
The error (in most instances) will also display the line of code throwing the error, or at least refer to it. Please show that line of code as well.

请先登录,再进行评论。

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-3-12
编辑:Dyuman Joshi 2023-3-12
@Muhammad Tarique, as Jan and Star Strider asked for - the full error message, which means all of the red text. Please keep that in mind.
For the error - You need to use ellipses (...) to continue the statement for defining the variable wavelets
%Go to the end of first two lines to see the usage of ellipses
wavelets = {'haar','db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10','sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', ...
'sym10','coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'bior1.1', 'bior1.3', 'bior1.5', 'bior2.2', 'bior2.4', 'bior2.6', 'bior2.8', 'bior3.1', 'bior3.3', 'bior3.5', ...
'bior3.7', 'bior3.9', 'bior4.4', 'bior5.5', 'bior6.8','rbior1.1', 'rbior1.3', 'rbior1.5', 'rbior2.2', 'rbior2.4', 'rbior2.6', 'rbior2.8', 'rbior3.1', 'rbior3.3', 'rbior3.5', 'rbior3.7', 'rbior3.9', 'rbior4.4', 'rbior5.5', 'rbior6.8', 'dmey', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22'}
wavelets = 1×62 cell array
{'haar'} {'db1'} {'db2'} {'db3'} {'db4'} {'db5'} {'db6'} {'db7'} {'db8'} {'db9'} {'db10'} {'sym2'} {'sym3'} {'sym4'} {'sym5'} {'sym6'} {'sym7'} {'sym8'} {'sym9'} {'sym10'} {'coif1'} {'coif2'} {'coif3'} {'coif4'} {'coif5'} {'bior1.1'} {'bior1.3'} {'bior1.5'} {'bior2.2'} {'bior2.4'} {'bior2.6'} {'bior2.8'} {'bior3.1'} {'bior3.3'} {'bior3.5'} {'bior3.7'} {'bior3.9'} {'bior4.4'} {'bior5.5'} {'bior6.8'} {'rbior1.1'} {'rbior1.3'} {'rbior1.5'} {'rbior2.2'} {'rbior2.4'} {'rbior2.6'} {'rbior2.8'} {'rbior3.1'} {'rbior3.3'} {'rbior3.5'} {'rbior3.7'} {'rbior3.9'} {'rbior4.4'} {'rbior5.5'} {'rbior6.8'} {'dmey'} {'fk4'} {'fk6'} {'fk8'} {'fk14'} {'fk18'} {'fk22'}
If you don't use ellipses, entering data in the next line is treated as next row, and in the manner you have written, the number of elements in each line are not same, thus you get the error for vertical concatenation.
%Example of the error
alphabet = {'a',
'b', 'c',
'd', 'e', 'f'}
Error using vertcat
Dimensions of arrays being concatenated are not consistent.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by