help me debug this script!

1 Ansicht (letzte 30 Tage)
Cside
Cside am 17 Sep. 2019
Kommentiert: Cside am 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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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.
  3 Kommentare
Walter Roberson
Walter Roberson am 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
Cside
Cside am 17 Sep. 2019
thank you Walter, really appreciate it :) have a good day!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by