lundi 10 août 2020

How can I create a subplot from for loop with an if statement or using any other suitable method

I have two threshold values (scalars) that I would like to run through my for loop, and subsequently plot each 'meanMUA' (for that particular threshold value) as a subplot.

I attempted the following, but the 'meanMUA' for threshold1 is subplotted in both specified positions, rather than the 'meanMUA' for threshold1 (in position 1) and threshold2 (in position 2):

threshold1 = 0.018; 
threshold2 = 2*threshold1;

figure;
for threshold = 1:2
    
    for trial = 1:50

        for channel = 1:16

            for bin = 1:10000

                %%access data from bins, using sliding window
                bindata = absData(((bin*binWidth)+1-binWidth : bin*binWidth), channel, trial);

                if threshold == threshold1 || threshold == threshold2

                    %%calculate mua above threshold
                    mua(bin, channel, trial) = sum(bindata >= threshold);

                end

            end

        end

    end
    
meanMUA = (mean(mua,3)).';

subplot(1,2, threshold);
clims=[0 1];
imagesc(meanMUA,clims)
 
end

I have attempted other variations of this code, including re-structuring the if/elseif statement and calculating the meanMUA for both thresholds within the if/elseif statement, though this doesn't work either:

if threshold == threshold1

        %%calculate mua above threshold
        mua(bin, channel, trial) = sum(bindata >= threshold);
        meanMUA = (mean(mua,3)).';
        
        subplot(1,2, threshold);
        clims=[0 1];
        imagesc(meanMUA,clims)

     elseif threshold == threshold2

        %%calculate mua above threshold
        mua(bin, channel, trial) = sum(bindata >= threshold);
        meanMUA = (mean(mua,3)).';
        
        subplot(1,2, threshold);
        clims=[0 1];
        imagesc(meanMUA,clims)
        
end

Does anyone know how I can solve this? Your help is appreciated.

I am using Matlab 2019b.

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire