9 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

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

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

- 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

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758137

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758137

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758152

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758152

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758154

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758154

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758155

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758155

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758165

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/486239-error-using-matrix-dimensions-must-agree#comment_758165

Sign in to comment.