WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

N-BACK trial order

 

Filomena
Forum-Newbie

Forum-Newbie


Beiträge: 5
Anmeldedatum: 10.04.20
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 15.06.2020, 18:16     Titel: N-BACK trial order
  Antworten mit Zitat      
Liebe Alle,
ich versuche eine N-Back Task zu programmieren und habe einen Beispiel Code, um die "trial-order" zu berechnen. Allerdings funktioniert er nicht, sondern spuckt mir immer wieder diese Fehlermeldung aus: "Index exceeds the number of array elements (4).

Error in nBackCreateTrialList_v1_2 (line 56)
trialListBlock(1, 1:trialsPerBlock(n)) = randi(10,1, trialsPerBlock(n));

Weiß jemand vielleicht wie ich das auflösen kann..?
Vielen Dank Smile

Code:
function [trialList, levels, blocks] = nBackCreateTrialList_v1_2(lowestLevel, highestLevel,trialsPerBlock ,targetsPerBlock, numOfBlocks)
%Creates stimuli list for n-back task.
% Version 1.2

    % Experimental variables
    % Number of trials etc.
    lowestLevel         = 1; % n
    highestLevel        = 4;
    numOfBlocks         = 3;
    targetsPerBlock     = 6;
    nonTargetsPerBlock  = 14; % + n
    trialsPerBlock      = []; % Number of trials for a block per level
    nTrial              = []; % Total number of trials per level
   
        for n = lowestLevel:highestLevel
        trialsPerBlock(n) = nonTargetsPerBlock + targetsPerBlock + n;
        nTrial(n)         = trialsPerBlock(n)*numOfBlocks;
        end
        totalNTrial        = sum(nTrial);
   
    trialList = [];
    levels    = [];
    blocks    = [];
    for n = lowestLevel:highestLevel
        disp(horzcat('Creating trial list for level n = ', num2str(n)))
        %  First try of creating trial list with targetsPerBlock
        for block      = 1:numOfBlocks
            targetCount    = 0; % Variable counting the n-back targets in a block
            levelsBlock    = zeros(1, trialsPerBlock(n)) + n; % Indicating the level of every trial
            blocksBlock    = zeros(1, trialsPerBlock(n)) + block; % Indicating the block of every trial
            trialListBlock(1, 1:trialsPerBlock(n)) = randi(10,1, trialsPerBlock(n)); % Indicating stimulus number
            trialListBlock(2, 1:trialsPerBlock(n)) = zeros(1, trialsPerBlock(n)); % Indicating target status

            % Counting the number of targetsPerBlock in trialListBlock
            for position = 1:length(trialListBlock)
                if position > n
                    if trialListBlock(1, position) == trialListBlock(1, position - n)
                        targetCount = targetCount + 1;
                        trialListBlock(2, position) = 1;
                    end
                end
            end
            moreThanThree = 0;
            for n = 1:length(trialListBlock) - 4 % Checking whether a stimulus more than three times
                if trialListBlock(1, n + 1) ==  trialListBlock(1, n + 2) &&  trialListBlock(1, n + 3) == trialListBlock(1, n + 1) &&  trialListBlock(1, n + 1) == trialListBlock(1, n + 4)
                    moreThanThree = 1;
                end
            end
            % Checking whether the number of targets in trialListBlock is
            % equal to targetsPerBlock
            if targetCount ~= targetsPerBlock || moreThanThree == 1% Not equal so do it again
               
                while targetCount ~= targetsPerBlock || moreThanThree == 1
                    targetCount    = 0;
                    moreThanThree  = 0;
                    trialListBlock(1, 1:trialsPerBlock(n)) = randi(10,1, trialsPerBlock(n));
                    trialListBlock(2, 1:trialsPerBlock(n)) = zeros(1, trialsPerBlock(n));
                    for position = 1:length(trialListBlock)
                        if position > n
                            if trialListBlock(1, position) == trialListBlock(1, position - n)
                                targetCount = targetCount + 1;
                                trialListBlock(2, position) = 1;
                            end
                        end
                    end
                    for n = 1:length(trialListBlock) - 4 % Checking whether a stimulus is repeated more than three times
                        if trialListBlock(1, n + 1) ==  trialListBlock(1, n + 2) &&  trialListBlock(1, n + 3) == trialListBlock(1, n + 1) &&  trialListBlock(1, n + 1) == trialListBlock(1, n + 4)
                            moreThanThree = 1;
                        end
                    end
                end
            end
                levels    = [levels levelsBlock];
                blocks    = [blocks blocksBlock];
                trialList = [trialList trialListBlock];
        end
    end
end
Private Nachricht senden Benutzer-Profile anzeigen


Harald
Forum-Meister

Forum-Meister


Beiträge: 24.448
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 15.06.2020, 19:13     Titel:
  Antworten mit Zitat      
Hallo,

meine Empfehlung: Haltepunkt in die Zeile setzen und die Dimensionen der beteiligten Variablen prüfen. Für weitere Unterstützung bitte auch den reproduzierbaren verwendeten Funktionsaufruf posten.

Grüße,
Harald
_________________

1.) Ask MATLAB Documentation
2.) Search gomatlab.de, google.de or MATLAB Answers
3.) Ask Technical Support of MathWorks
4.) Go mad, your problem is unsolvable ;)
Private Nachricht senden Benutzer-Profile anzeigen
 
Filomena
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 5
Anmeldedatum: 10.04.20
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 17.06.2020, 12:16     Titel: N-Back trial order
  Antworten mit Zitat      
Danke Smile !

Ich verstehe nur nicht wieso diese Fehlermeldung erst in Zeile 56 kommt, derselbe Code aber vorher in den Zeilen 20.. ausgeführt werden kann..?


Code:
[trialList, levels, blocks] = nBackCreateTrialList(lowestLevel, highestLevel,trialsPerBlock ,targetsPerBlock, numOfBlocks);
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


Beiträge: 24.448
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 17.06.2020, 13:54     Titel:
  Antworten mit Zitat      
Hallo,

Zitat:
Ich verstehe nur nicht wieso diese Fehlermeldung erst in Zeile 56 kommt, derselbe Code aber vorher in den Zeilen 20.. ausgeführt werden kann..?

Vermutlich weil die Dimensionen der beteiligten Variablen unterschiedlich sind. Ich kann nur Debuggen empfehlen.

Zitat:
[trialList, levels, blocks] = nBackCreateTrialList(lowestLevel, highestLevel,trialsPerBlock ,targetsPerBlock, numOfBlocks);

Das ist der allgemeine Aufruf. Um dir helfen zu können, brauche ich aber einen speziellen Aufruf mit Werten für die Eingabeargumente.

Grüße,
Harald
_________________

1.) Ask MATLAB Documentation
2.) Search gomatlab.de, google.de or MATLAB Answers
3.) Ask Technical Support of MathWorks
4.) Go mad, your problem is unsolvable ;)
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.