help me debug this script!

1 次查看(过去 30 天)
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
Walter Roberson 2019-9-17
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.
  3 个评论
Walter Roberson
Walter Roberson 2019-9-17
%%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
Cside
Cside 2019-9-17
thank you Walter, really appreciate it :) have a good day!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Analysis of Variance and Covariance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by