Indexing numbers only finding NaN

2 views (last 30 days)
Catherine
Catherine on 30 May 2023
Commented: Walter Roberson on 31 May 2023
Hi, all,
I am trying to index values from my files that are before a switch condition. The code knows the read at the switch, but I need the value before. I have been messing with it for a couple work days.
%Find the indices of trials before the side of weight switches in object
indxTrialBeforeWeightSwitch = indxMinoritySide-1;
%only use the positive values (otherwise includes if there was a weight switch)
positiveIndices = find(indxTrialBeforeWeightSwitch>0);
indxTrialBeforeWeightSwitch = indxTrialBeforeWeightSwitch(positiveIndices);
%make vectors to store the data:
currentSeqMComValues = NaN(maxSeqReps, 1);
MComBeforeSwitch = NaN(maxSeqReps, 1);
currentSeqTrialNums = NaN(maxSeqReps, 1);
trialBeforeMComSwitch = NaN(maxSeqReps, 1)
%store the ouptut of the trials before the CoM switch
trialBeforeSwitchVec = [trialBeforeSwitchVec, trialBeforeMComSwitch'];
MComBeforeSwitch = [MComBeforeSwitch, currentMCOMBeforeSwitch'];
This is what I currently am looking at. All I get for all the variables listed above, except for currentMComBeforeSwitch, is NaN.
Sorry if this is not enough information, I am still in my learning stages of matlab.
Thank you!
  3 Comments
Catherine
Catherine on 31 May 2023
I am not sure what you are asking. When looking at the data, I can see that there are mostly positive values for minorityside-1. If you're asking if I made space for the data to go, I did do that too. Thank you!!
Walter Roberson
Walter Roberson on 31 May 2023
trialBeforeSwitchVec = [trialBeforeSwitchVec, trialBeforeMComSwitch'];
We are not given any information about trialBeforeSwitchVec. But we know that trialBeforeMComSwitch was assigned on the line above according to
trialBeforeMComSwitch = NaN(maxSeqReps, 1)
You appear to be building up trialBeforeSwitchVec incrementally, and you do not show any code in which you put any non-nan value into trialBeforeMComSwitch so it would not be surprising at all to discover that afterwards the entire trialBeforeMComSwitch is NaN.
MComBeforeSwitch = NaN(maxSeqReps, 1);
All NaN.
MComBeforeSwitch = [MComBeforeSwitch, currentMCOMBeforeSwitch'];
We have no information about currentMCOMBeforeSwitch but MComBeforeSwitch was assigned NaN.
If currentMCOMBeforeSwitch has even one non-NaN value then [MComBeforeSwitch, currentMCOMBeforeSwitch'] must have at least one non-NaN entry unless the [] fails.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!