Error using - Matrix dimensions must agree.

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
per isakson 2019 年 10 月 19 日
I tried to run your code and got
>> imf = tvf_emd( DS_DATA_ODU )
Undefined function or variable 'INST_FREQ_local'.
Error in tvf_emd (line 70)
[instAmp0,instFreq0] = INST_FREQ_local(y);
70 [instAmp0,instFreq0] = INST_FREQ_local(y);
I cannot spot the error by inspection of the code.
Yussif M. Awelisah
Yussif M. Awelisah 2019 年 10 月 19 日
I sincerely appreciate your concern help.
Please the attached has all functions required.
per isakson
per isakson 2019 年 10 月 19 日
Did you edit the question? However, to help I need INST_FREQ_local.m
Yussif M. Awelisah
Yussif M. Awelisah 2019 年 10 月 19 日
Please I did not. I have attached that.
per isakson
per isakson 2019 年 10 月 19 日
We wrote our comments at the same time, which explains the confusion.

サインインしてコメントする。

 採用された回答

per isakson
per isakson 2019 年 10 月 19 日
編集済み: per isakson 2019 年 10 月 23 日

0 投票

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 件のコメント

Yussif M. Awelisah
Yussif M. Awelisah 2019 年 10 月 19 日
I changed the line as follows but the error still persist.
if(numel([indmin_x, indmax_x])<4)
imf(nimf,:)=temp_x( some_index, : );
if numel(find(temp_x~=0))>0
nimf=nimf+1;
the error still occurs as
Error using -
Matrix dimensions must agree.
Error in tvf_emd (line 136)
temp_x = temp_x-y(ind_remov_pad);
per isakson
per isakson 2019 年 10 月 19 日
編集済み: per isakson 2019 年 10 月 19 日
From that we learn
  • the line imf(nimf,:)=temp_x( some_index, : ); isn't executed in your code because otherwise it had thrown an error. some_index in my answer is a placeholder for an appropriate index that you have to fill in. Only you know the intent of that line.
  • you didn't respond when I told you what release I'm running.
  • you didn't respond to my assumption that we are running different versions of your code
  • you didn't apply the approach I proposed, namely dbstop if error and whos variables of interest at the error
Yussif M. Awelisah
Yussif M. Awelisah 2019 年 10 月 20 日
sorry for the delay response, it was mid- night here and I had to leave the lab.
The version of the of tvf_emd code I attached is my modified version to be able to work with the matrices. The original version(can be found at file exchange) seems to be only made to work with vectors. the error of ''horzcat'' occurs when I tried running the original version with the matrix data I attached.
I am using matlab R2015a .
at this point the version of my code and the data attached shows only the below error:
Error using -
Matrix dimensions must agree.
Error in tvf_emd (line 136)
temp_x = temp_x-y(ind_remov_pad);
I will be grateful if you can run the attached version of the code and data and see how best this error can be resolved or the attached data and the original version .
per isakson
per isakson 2019 年 10 月 22 日
編集済み: per isakson 2019 年 10 月 22 日
"run the attached version of the code" In my answer, I've done that and reported that I encountered a different error. The reason for the different errors might (long shot) be that my R2018b supports Compatible Array Sizes for Basic Operations, whereas R2015a doesn't do that.
"error can be resolved" If you can make this code run, what support are there, it would produce the expected result?
"shows only the below error" Yes, Matlab shows the first error it encounters and quits the execution. When you fixed the first error, Matlab will hit the second error. This will repeat until you fixed the last error.
per isakson
per isakson 2019 年 10 月 22 日
I added an alternative solution to my answer.
Yussif M. Awelisah
Yussif M. Awelisah 2019 年 10 月 23 日
編集済み: per isakson 2019 年 10 月 23 日
imf_array = tvf_emd( DS_DATA_ODU )
len = size( DS_DATA_ODU, 1 );
imf_array = cell( len, 1 );
for jj = 1 : len
imf_array{jj} = tvf_emd( DS_DATA_ODU(jj,:) );
end
end
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in tvf_emd (line 48)
y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
48 y = [fliplr(y(2:2+num_padding-1)) y fliplr(y(end-num_padding:end-1))]; % padding to deal with boundary effect (symmetric)
I am humbled and grateful for your concern. I tried both alternatives you provided but both still throws the above error.
per isakson
per isakson 2019 年 10 月 23 日
What are you trying to do?
Why not first try my code?
Do you understand what I propose?
Yussif M. Awelisah
Yussif M. Awelisah 2019 年 10 月 23 日
"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 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
  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 2019 年 10 月 23 日
this worked and I am sincerely grateful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by