How to increase count for different counters in if loop.

조회 수: 5 (최근 30일)
Alice
Alice 2015년 2월 18일
댓글: Alice 2015년 2월 18일
I'm trying to make a counter during iterations of trials. I've been using the code below. I want count, fillcount and expcount to increase. However fillcount and expcount can only increase when a certain variable (itemtype) is a certain number.
when I run this code count increases but expcount and fillcount don't but I don't know why. All help is greatly appreciated!
a=ones(length(item),1);%vector of 1s for number of experimental pairs
b=2*ones(length(fillerorder),1); %vector of 2s for number of fillers
c=[a;b];
itemtype=c(randperm(numel(c)));%vector of 1s and 2s, 1=experimentalpair 2=filler
fillcount=1;
expcount=1;
count=0;
while count<=9
count=count+1;
if itemtype==1
fillcount=fillcount;
fillcount=fillcount+1 %increase counter by 1
elseif itemtype==2
expcount=expcount;
expcount=expcount+2 %increase counter by 2
end
end

채택된 답변

A Jenkins
A Jenkins 2015년 2월 18일
You are comparing the entire itemtype array to the numbers 1 and 2. Perhaps you want to compare just one element of the array?
if itemtype(count)==1
..
elseif itemtype(count)==2
..
  댓글 수: 1
Alice
Alice 2015년 2월 18일
Thank you so much! I knew it was something like that but couldn't for the life of me figure it out! You have saved me days!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by