# help me debug this script!

3 views (last 30 days)
Charms on 17 Sep 2019
Commented: Charms on 17 Sep 2019
Hi I have this script:
%%this script produces the anova1 values for n1-35 in session 1
n = 1:35
dataset_pfc_tar_57_n = dataset_pfc_tar_57(n,:)
%%toreplicate into 8 rows
testdata_n = repmat(dataset_pfc_tar_57_n, 8,1)
pfc_n = testdata_n.*ixCopy
%%to Nan only those in ixCopy, not actual 0 values in dataset
pfc_n (ixCopy ==0) = NaN
%%transpose pfc_n for anova to work
p = anova1(pfc_n')
With this, I am returned with the prompt: Matrix dimensions must agree. However, I am unable to find out where they do not agree.
testdata_n = 8 x 621 double
ixCopy = 8 x 621 logical
The goal is to have the script produce 35 pvalues. Let me know the improvements I should make to my script. Thank you, any help is much appreciated!

Walter Roberson on 17 Sep 2019
n = 1:35
dataset_pfc_tar_57_n = dataset_pfc_tar_57(n,:)
With n being a vector of length 35, dataset_pfc_tar_57_n is going to have 35 rows and some number of columns that I will call COL
testdata_n = repmat(dataset_pfc_tar_57_n, 8,1)
Those rows are going to be replicated 8 times, giving you 280 rows and COL columns.
pfc_n = testdata_n.*ixCopy
You are multiplying a 280 x COL matrix element-wise by something you have said is 8 x 621. We could hypothesize that COL is 621, so the widths might be equal, but you cannot use .* between a 280 x 621 and an 8 x 621.
Now, if n were a scalar instead of a vector then everything would work out.

Charms on 17 Sep 2019
yep, I intend to have n as a scalar, i.e. running the script 35 times separately, with n from 1 - 35. How could I edit it to ensure this?
Walter Roberson on 17 Sep 2019
%%this script produces the anova1 values for n1-35 in session 1
p = zeros(1,35);
for n = 1:35
dataset_pfc_tar_57_n = dataset_pfc_tar_57(n,:)
%%toreplicate into 8 rows
testdata_n = repmat(dataset_pfc_tar_57_n, 8,1)
pfc_n = testdata_n.*ixCopy
%%to Nan only those in ixCopy, not actual 0 values in dataset
pfc_n (ixCopy ==0) = NaN
%%transpose pfc_n for anova to work
p(n) = anova1(pfc_n');
end
Charms on 17 Sep 2019
thank you Walter, really appreciate it :) have a good day!