Error using - Matrix dimensions must agree.
1 次查看(过去 30 天)
显示 更早的评论
please I will be grateful for any help for this error:
Error using -
Matrix dimensions must agree.
Error in tvf_emd (line 136)
temp_x = temp_x-y(ind_remov_pad);
the code is below:
if flag_stopiter
imf(nimf,:)=y(ind_remov_pad);
temp_x = temp_x-y(ind_remov_pad);
break;
end
5 个评论
采纳的回答
per isakson
2019-10-19
编辑:per isakson
2019-10-23
I get a different error. One reason for the difference in the wording is that we run different releases of Matlab(?). I run R2018b. However, more important it seems we are running different versions of your program. (Note: The line number might differ, since I have deleted some blank lines.)
>> dbstop if error
>> imf = tvf_emd( DS_DATA_ODU )
Unable to perform assignment because the size of the left side is 1-by-500 and the size of the right side is 231-by-500.
Error in tvf_emd (line 39)
imf(nimf,:)=temp_x;
39 imf(nimf,:)=temp_x;
K>> whos imf nimf temp_x
Name Size Bytes Class Attributes
imf 50x500 200000 double
nimf 1x1 8 double
temp_x 231x500 924000 double
K>> nimf
nimf =
18
This error is because you cannot overwrite one row of imf by the full matrix temp_x. The error of your question is most likely of the same kind.
The line imf(nimf,:)=temp_x; should probably be imf(nimf,:)=temp_x( some_index, : ) ;
In response to comment
If it ain't broke, don't fix it
"The original version [of tvf_emd] can be found at file exchange" Yes, I found Time varying filter based empirical mode decomposition(TVF-EMD). In the example, signal_decomposition.m, the function, tvf_emd, takes a row vector (signal) and returns a matrix. The number of rows of the output matrix depends on the input signal. There is no indication that the functions could take a matrix, i.e. many signals, as input. The documentation of tvf_emd isn't enough to make major modifications of the code - IMO.
Your goal is to make a function that takes a matrix. And returns what? Simplest first, make a wrapper. Try
>> imf_array = my_tvf_emd( DS_DATA_ODU );
>> whos imf_array DS_DATA_ODU
Name Size Bytes Class Attributes
DS_DATA_ODU 231x500 924000 double
imf_array 231x1 11129872 cell
where
function imf_array = my_tvf_emd( signals )
len = size( signals, 1 );
imf_array = cell( len, 1 );
for jj = 1 : len
imf_array{jj} = tvf_emd( signals(jj,:) );
end
end
10 个评论
per isakson
2019-10-23
编辑:per isakson
2019-10-23
I tried to convince you not to modify tvf_emd. It's difficult and you will probably never get it right. Thus use tvf_emd as it comes from the FEX.
As an alternative I proposed a Wrapper function, which I called my_tvf_emd. Your comment (2+ hour ago) doesn't show that you tried my_tvf_emd. On the contrary you copied and modified pieces of my code.
The line (the first line of your script)
imf_array = tvf_emd( DS_DATA_ODU )
will certainly cause an error. We know that by now. The function, tvf_emd, expects a vector. Respect that.
Do exactly the following steps
- Create the wrapper, my_tvf_emd. Copy the code below the word "where" to an empty editor "document" and save it to a file named my_tvf_emd.m
- Make sure that tvf_emd invokes the file from the fex-submission. Not one of your modified versions. Run which tvf_emd -all The fex version shall appear at the top of the result.
- In the command window run (I used >> to indicate command window.)
imf_array = my_tvf_emd( DS_DATA_ODU );
whos imf_array DS_DATA_ODU
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!