Frage

I have data for 72 trials, some trials are usable, some are not. The trials start and end are specified by two cells "First_scans" (i.e., the first scan of the trials) and "Last_scans" (the last scan of the trials). Thus, the First_scans is a 72x1 cell (the values are 1, 15, 25, 46 etc.). The Last_scan is also a 72x1 cell (the values are 10, 23, 38 etc.). The trials have different lengths and are not continuous. Now, I have another cell named Bad_scans containing scans that are not usable. This is an nx1 cell which has values like 14, 15, 16, 26, 38 etc. Since the trials are not continuous, some of the bad_scans may not be part of a trial.

With all that in mind, I would like to find out which trials these bad_scans below to (if they do belong to a trial at all). A bad_scan belongs to a trial if it falls between the start and end scan of that trial. For instance, following the previous example, the scan 14 does not belong to any trial. The second and third bad_scans are 15, and 16 and thus belong to trial 2. The fourth bad_scan belongs to the third trial. How would I get a summary of which trials contain bad_scans?

Thank you!

War es hilfreich?

Lösung

here is something that might help; for the sake of argument I'm using length 3 rather than 72:

first_scans={1;2;9};
last_scans={3;4;5};
bad_scans={4;7};

fs=cell2mat(first_scans);
ls=cell2mat(last_scans);
bs=cell2mat(bad_scans);

trials=cat(2,fs,ls);
bad_trials=zeros(0,0);

for i=1:size(trials,1)
    if any(ismember(bs,trials(i,:)))
        bad_trials=cat(2,bad_trials,i);
    end
end

disp(bad_trials)

Andere Tipps

Try the following: this loops over each pair of start/end values, and determines whether any of the values occurs in the list of bad scans. It is possible to write this as a "vectorized" method at the expense of clarity - and with just 72 scans, the performance penalty is not worth the trouble of writing hard-to-understand code.

bad_runs = cell(1,72);
containsBad = zeros(1,72);
bad_scans = cell2array(bad_scans);
for ii = 1:72
  temp = First_scans{ii}:Last_scans{ii};
  containsBad = (numel(intersect(temp, bad_scans))>0);  
end

Summary of all the ones that contain bad scans:

disp(find(containsBad));

Assuming:

First_scans = {1; 15; 25; 46}
Last_scan = {10; 23; 38; 50}
Bad_scans = {14; 15; 16; 26; 38}

You could do it like this:

find(arrayfun(@(x) any(First_scans{x} <= [Bad_scans{:}] & Last_scan{x} >= [Bad_scans{:}]), 1:numel(First_scans)))

ans =

     2     3

Which means trials 2 and 3 contains bad scans.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top