error only showing up with one for loop -- can't figure out what the problem is? going crazy?

1 回表示 (過去 30 日間)
nines
nines 2020 年 1 月 7 日
編集済み: dpb 2020 年 1 月 8 日
Hello all!
I am running for loops on timeseries that I have put into an array, and then I calculated the power. I then just want to put it into a matrix -- and this has worked and was working until a couple of hours ago.
The first for loop works and the second one does not. The error is:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 257-by-1.
Error in power_and_scatter_plots (line 45)
allspectrums_ventricle_young(a,:) = power_ventricle_young;
I've stepped through all the variables to double check that are consistent with their values, and they are! I even took a break and stepped back to see if I could spot an error when i came back -- no luck. Has anyone run into this problem, and does anyone have any suggestions?
%% 1) adding paths
addpath(genpath(pwd))
%% 2) mr spectogram for each subject
%params
dt = .800;
params.tapers=[2 3];
params.fs=1/dt;
%% 3) defining ts for elderly and youth
%a) youth cortex and ventricle
y_cortex_detrended = {y_d_c_ts_1 y_d_c_ts_2 y_d_c_ts_3 y_d_c_ts_4 y_d_c_ts_5 y_d_c_ts_8 y_d_c_ts_10}
y_ventricle_detrended = {y_d_v_ts_1 y_d_v_ts_2 y_d_v_ts_3 y_d_v_ts_4 y_d_v_ts_5 y_d_v_ts_8 y_d_v_ts_10}
%b) elderly cortex and ventricle
e_cortex_detrended = {d_c_ts_1 d_c_ts_2 d_c_ts_3 d_c_ts_4 d_c_ts_6 d_c_ts_7 d_c_ts_8 d_c_ts_10}
e_ventricle_detrended = {d_v_ts_1 d_v_ts_2 d_v_ts_3 d_v_ts_4 d_v_ts_6 d_v_ts_7 d_v_ts_8 d_v_ts_10}
%% 4) power for loops
%youth c - this works!!!!!!
%
for a = 1:length(y_cortex_detrended)
name = y_cortex_detrended{a}
[power_cortex_young, f] = mtspectrumc(name,params) %detrended cortex young person
allspectrums_cortex_young(a,:) = power_cortex_young; %matrix
end
% % %youth v -- this does not!!!!
%
for a = 1:length(y_ventricle_detrended)
name = y_ventricle_detrended{a}
[power_ventricle_young, f] = mtspectrumc(name,params) %detrended cortex young person
allspectrums_ventricle_young(a,:) = power_ventricle_young;
end
  1 件のコメント
per isakson
per isakson 2020 年 1 月 7 日
To help those, who want to try their solution before answering, upload the data needed to run your script (in a mat-file) or a script that creates the data.

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

採用された回答

dpb
dpb 2020 年 1 月 7 日
編集済み: dpb 2020 年 1 月 8 日
Unable to perform assignment because the size of the left side is 1-by-1
and the size of the right side is 257-by-1.
Error in power_and_scatter_plots (line 45)
allspectrums_ventricle_young(a,:) = power_ventricle_young;
You've apparently already defined allspectrums_ventricle_young from a previous run and haven't cleared it. Now you're trying to put a 257-long column array into a row of the existing array.
Add a
clear allspectrums_ventricle_young
before beginning the loop. But, unless there are exactly the same number of elements for each pass, you'll have a problem of mismatched sizes when that does occur (if it does).
I'd write
allspectrums_ventricle_young(a,:)=power_ventricle_young.';
to match up the orientations.
  1 件のコメント
nines
nines 2020 年 1 月 8 日
that works!! thank you so so much, i've been trying to figure this out all day!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFrequently-used Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by