Sum Array command
MEDState Notation Repository › Forums › Coding Help Archive › Sum Array command
- This topic has 3 replies, 1 voice, and was last updated 8 years, 9 months ago by
Med_Support.
-
AuthorPosts
-
December 13, 2016 at 3:23 pm #12704
Med_Support
Moderatorvestela
I am trying to figure out how to properly use the “SumArray” command. It would be part of a state set that is computing trials to criterion within an array. “Trials to criterion” in this case means 10 of the last 12 trials were correct (in a spatial memory task). So we are using the array such that if the trial was correct, a “1” is put into the array, and if it is incorrect, a “0” is put in. The array would then be summed following each trial to see if it equals 10. What I have right now is:
S1, \Start #Z^ChoicePhase: ---> S2 S2, 0.001": IF (Z(Y+4) = 3) OR (Z(Y+4) = 6) [@oneobject, @continue] @oneobject: ---> S1 @continue: --->S3 S3, 0.001": SET K = 0; IF Z(Y+4) = Z(Y+5) [@correct, @incorrect] @correct: SET U(K) = 1; ---> S4 @incorrect: SET U(K) = 0; ---> S4 S4, 0.001": SET K = K + 1; IF K > 11 [@reset, @continue] @reset: SET K = 0; ---> S5 @continue: --->S5 S5, 0.001": SumArray S=U, 0, I; IF S = 10 [@criterion, @continue] @criterion: SET G(^TTC) = A(^Trials); --->SX @continue: ---> S1
Z^ChoicePhase is a Z-pulse that indicates the animal has completed fixation and will be making a choice. In S2, we have single object probe trials that I would like to exclude from the calculation. S3 is where I am beginning the index. S4, we are advancing the index. S5 is where I am trying to do the computation. I do not get any errors when compiling this, but when I try to run it, ^TTC does not register anything. I can send my whole code if necessary, but the fact that I’m not getting errors indicates to me that I am simply not understanding how to correctly execute that one command, and not that it’s something intrinsically wrong with the set-up.
Please let me know if you have any ideas. Thanks!
December 13, 2016 at 3:40 pm #12703Med_Support
ModeratorGary Bamberger
Hi,
I think that the problem is in S3. Every single time that state executes you are setting K = 0. So you are always assigning the value to U(0).
In S5 I am not certain where the value I comes from. It may be set elsewhere in your code and contain the correct value, but I can’t tell from the code snippet that you included.
Please let me know if this information helps or if you still have problems.
Best Regards,
GaryDecember 13, 2016 at 3:59 pm #12707Med_Support
Moderatorvestela
The value I comes from the Trans IV translator help about SumArray: “Notice that a variable, I, is used in the call to HarmonicMean to indicate the last element in the C array that should be included in the calculation. Variable I tracks the number of completed ratios and is incremented after the call to HarmonicMean.” (It’s the only example included for the statistical commands)
Also, if I try to take it out, I get errors that “A constant is missing ‘^’ or undeclared constant or attempt to change the value of a constant”
I took out that K = 0 from S3, but it still isn’t working. Should I email you the entire file of code?
Thank you for your help.
December 13, 2016 at 4:25 pm #12709Med_Support
ModeratorThe SUMARRAY command takes four parameters.
The 1st is the variable that you want the summed value to be placed into. In your case this is the variable S.
The 2nd is the array that you want summed. In your case this is the array U.
The 3rd is the location in the array where the summing should begin. Most of the time this is 0, but it does not have to be.
The 4th is the location in the array where the summing should end. Most of the time this is the last element in the array, but it does not have to be.So if you are trying to sum up the results from the last 10 trials in array U, then the command would be:
SUMARRAY S = U,0,9
Another thing that I just noticed is in S4 you are checking IF K > 11 [@Reset, @Continue]
If you are trying to sum up the results from the last 12 trials, then this is correct.
If you are trying to sum up the results from the last 10 trials, then you will want to change this to IF K >= 10 [@Reset, @Continue]If you are trying to sum up the results from the last 12 trials in array U, then the command would be:
SUMARRAY S = U,0,11
If that doesn’t solve the problem, then please email me the entire program and I will be happy to take a look at it for you.
Best Regards,
Gary -
AuthorPosts
- You must be logged in to reply to this topic.