From: gunther on 16 Jul 2010 18:19 Hello! I would like to do the following: A=zeros(2) is a predefined 2*2 matrix I want to fill this matrix to indicate the frequencies of 4 different events whose occurrence is evaluated in the course of a conditional statement that is nested in a for loop for i=1:10 if event_1 ==1 add 1 to A(1,1) elseif event_2 ==1 add 1 to A(1,2) elseif event_3 ==1 add 1 to A(2,1) else add 1 to A(2,2) end end e.g. A= 3 4 2 1 would state that event_1 occurred 3 times, event_2 4 times, etc. How can I do this while keeping the for loop as well as the conditional statement? I would be glad if you could help me with this Many thanks! forben
From: Nathan on 16 Jul 2010 18:39 On Jul 16, 3:19 pm, "gunther " <for...(a)web.de> wrote: > Hello! > > I would like to do the following: > > A=zeros(2) is a predefined 2*2 matrix > > I want to fill this matrix to indicate the frequencies of 4 different events whose occurrence is evaluated in the course of a conditional statement that is nested in a for loop > > for i=1:10 > > if event_1 ==1 > > add 1 to A(1,1) > > elseif event_2 ==1 > > add 1 to A(1,2) > > elseif event_3 ==1 > > add 1 to A(2,1) > > else > > add 1 to A(2,2) > > end > > end > > e.g. A= 3 4 > 2 1 would state that event_1 occurred 3 times, event_2 4 times, etc. > > How can I do this while keeping the for loop as well as the conditional statement? > > I would be glad if you could help me with this > Many thanks! > forben Simple case: for i=1:10 if event_1 ==1 A(1,1) = A(1,1) + 1 elseif event_2 ==1 A(1,2) = A(1,2) + 1 elseif event_3 ==1 A(2,1) = A(2,1) + 1 else A(2,2) = A(2,2) + 1 end end All you had to do was write it out. -Nathan
From: Jan Simon on 17 Jul 2010 08:09 Dear Nathan, You have converted: > > add 1 to A(1,1) to > A(1,1) = A(1,1) + 1 I do not find the right words to comment that. It reminds me to a workmate, who had to write a text about the topic "what is bold". Her text was firm: "This is bold." Actually it is not needed to mention, that she had passed the exam. kind regards, Jan
|
Pages: 1 Prev: Need stp.dll file for running Stepper motor via parallel port Next: path for non .m files? |