MATLAB Answers

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

2 views (last 30 days)
nines
nines on 7 Jan 2020
Edited: dpb on 8 Jan 2020
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 Comment

per isakson
per isakson on 7 Jan 2020
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.

Sign in to comment.

Accepted Answer

dpb
dpb on 7 Jan 2020
Edited: dpb on 8 Jan 2020
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 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by