fill value that has different size of array

5 ビュー (過去 30 日間)
상훈 송
상훈 송 2022 年 9 月 12 日
コメント済み: 상훈 송 2022 年 9 月 13 日
I'm using matlab function emd for decomposing signals. I have a 10 different sets of signals however, for example, one signal from 10 is decomposed into 8 imf and 1 residual and another one signal is decomposed into 9 imf and 1 residual. I would like to fill the array with NaN value that has smaller number of decomposed imf compared to the longest one using for loop..
1_imfs = {10001x8} 2_imfs = {10001x9} ....
1_residual = {10001x1} 2_residual = {10001x1} .....
Here is the code that i've tried..
for i = 1:10
input_imfs = NaN(10,10001,10);
input_res = NaN(10,10001);
[input_imfs(i,:,:),input_res(i,:)] = emd(Data_input_acc(i,:));


Jeffrey Clark
Jeffrey Clark 2022 年 9 月 13 日
@상훈 송, trying to save results directly into part of an array will not work unless you know exactly what the size of the return will be so that you can replace the ':'s in the left side of the assignment. But this will work (note that the input_varables must be defined before the loop):
input_imfs = NaN(10,10001,10);
input_res = NaN(10,10001);
for i = 1:10
[imfs,res] = emd(Data_input_acc(i,:));
input_imfs(i,1:size(imfs,1),1:size(imfs,2)) = imfs;
input_res(i,1:length(res)) = res;
  1 件のコメント
상훈 송
상훈 송 2022 年 9 月 13 日
Thank you so much... It worked perfectly well!


その他の回答 (0 件)


Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索



Community Treasure Hunt

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

Start Hunting!

Translated by