writing code so that for loop does not overwrite

Hi, I currently have this code and would like to NOT have the for loop overwrite with every t so that there will be 11 selectiven. How can i rewrite the problem line to make sure the for loop does not overwrite and produce 11 selectiven matrices? Thank you! :)
for t = 43:53
C= A(:,:,t);
for i = 1:8
D = find(sessions_pfc==i);
trialsize = size(trials(i).val);
B = ix_all(i);
B2 = cell2mat(B);
[locations,~] = find(B2);
anss = 0;
for n = D(1,:):D(end)
p= anova1(C(n,1:trialsize(:,2)), locations', 'off');
anss=anss+(p<0.05);
selectiven (n,:) = p<0.05
end
end
neuronno(t) = find (selectiven); %%problem line
end

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 1 Déc 2019
Modifié(e) : KALYAN ACHARJYA le 1 Déc 2019
#Edited
neuronno(t) = find (selectiven);
As the t indices starts from 43 till 53. Here what about the previous indexing? Better to choose other variable name to avoid zeros or [ ] at initials-
%Drfine k=1 before first for loop
neuronno(k) = find (selectiven);
k=k+1;
Still problem, let me kow?

5 commentaires

Cside
Cside le 1 Déc 2019
hi Kalyan, there should be 11 selectiven produced from t = 43:53. It will not be based off n as not all n loops fit the requirement of p<0.05. Hence, wouldn't it be neuronno(t) instead?
Thanks!
KALYAN ACHARJYA
KALYAN ACHARJYA le 1 Déc 2019
Modifié(e) : KALYAN ACHARJYA le 1 Déc 2019
ohh sorry,my bad. After execute the code, can you share the following
>>whos neuronno
Also
>> whos selectiven
Cside
Cside le 1 Déc 2019
Modifié(e) : Cside le 1 Déc 2019
ok i have edited the code but the error "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side" appeared when i typed neuronno(k) as suggested. I tried with neuronno_k but it does not give me 11 new matrices (desired), just one.
I also tried to write neuronno = zeros(size(selectiven,1),1) to create the desired size vector of neuronno_k with zeros first but it doesn't seem to work.
//
for the whos details, neuronno is not valid when it is neuronno(k). For selectiven,
Name Size Bytes Class Attributes
selectiven 226x1 1808 double
KALYAN ACHARJYA
KALYAN ACHARJYA le 1 Déc 2019
Modifié(e) : KALYAN ACHARJYA le 1 Déc 2019
OK, May be in each iteration the following statement gives the same results
>> find(selectiven)
ans =
1
Right? Is this statement complete? Based on my basic undestanding you may get the following results for neuronno
neuronno=[0 0 0 0 0.....................till 42 index then 1 1 1 1 1 1 1 1 1 1]
Cside
Cside le 1 Déc 2019
every selectiven will be 226x1. However, find(selectiven) will give a different answer with each iteration as selectiven is a logical matrix, yielding an ans from 40-80.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Question posée :

le 1 Déc 2019

Modifié(e) :

le 1 Déc 2019

Community Treasure Hunt

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

Start Hunting!

Translated by