MATLAB Answers

Error using - Matrix dimensions must agree.

8 views (last 30 days)
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 Comments

Show 2 older comments
per isakson
per isakson on 19 Oct 2019
Did you edit the question? However, to help I need INST_FREQ_local.m
Yussif M. Awelisah
Yussif M. Awelisah on 19 Oct 2019
Please I did not. I have attached that.
per isakson
per isakson on 19 Oct 2019
We wrote our comments at the same time, which explains the confusion.

Sign in to comment.

Accepted Answer

per isakson
per isakson on 19 Oct 2019
Edited: per isakson on 23 Oct 2019
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 Comments

Show 7 older comments
Yussif M. Awelisah
Yussif M. Awelisah on 23 Oct 2019
"What are you trying to do?"
I tried runing both codes you sent earlier. I runned it as a 'script' in the command section to call out tvf_emd or do I have to modify the tvf_emd code with your code?
Why not first try my code?
>> 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
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
I tried both of these codes.
I dont if what I did is right. I hope I can understand you further
per isakson
per isakson on 23 Oct 2019
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
  1. 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
  2. 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.
  3. 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
Yussif M. Awelisah
Yussif M. Awelisah on 23 Oct 2019
this worked and I am sincerely grateful.

Sign in to comment.

More Answers (0)


Translated by