-
Notifications
You must be signed in to change notification settings - Fork 32
Error using reshape - single-level mediation walkthrough, publish_mediation_report #36
Description
Hi there,
I've been trying to use the single-level mediation function but encountered issues both when using my own data but then also when trying to simply follow the tutorial exactly step-by-step.
Here is the code I use for the tutorial:
%add path to required directories
addpath(genpath('/mnt/nfs/proj/rbs/Julia/MediationToolbox'));
addpath(genpath('/mnt/nfs/proj/rbs/Julia/CanlabCore'));
addpath(genpath('/mnt/nfs/proj/rbs/Julia/RS_Analysis'));
addpath('/mnt/nfs/proj/rbs/Julia/spm12');
%make directory and go to it
andir = '/mnt/nfs/proj/rbs/Julia/RS_Analysis/M3tutorial/Test_mediation';
mkdir(andir);
cd(andir);
%load image data and behavioural variables
dinf = what('Wager_et_al_2008_Neuron_EmotionReg');
gunzip(fullfile(dinf(1).path, 'Wager_2008_emo_reg_vs_look_neg_contrast_images.nii.gz'));
imgs = fullfile(dinf(1).path, 'Wager_2008_emo_reg_vs_look_neg_contrast_images.nii');
behav_dat = importdata(fullfile(dinf(1).path, 'Wager_2008_emotionreg_behavioral_data.txt'));
%load and display mask
mask = which('gray_matter_mask.nii');
canlab_results_fmridisplay(mask, 'full');
%run mediation
x=behav_dat.data(:,1);
y=behav_dat.data(:,2);
names={'X:RVLPFC' 'Y:Reappraisal_Success' 'M:BrainMediator'};
results=mediation_brain(x, y, imgs, 'names', names, 'mask', mask, 'boot', 'pvals', 5, 'bootsamples', 1000);
%generate results tables and figures
publish_mediation_report;
Here is the error that I am getting (exact same error when I use my own data, which makes me wonder if it's a matlab issue rather than a data issue):
publish_mediation_report;
Creating HTML report for results in:
/mnt/nfs/proj/rbs/Julia/RS_Analysis/M3tutorial/Test_mediation
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate
size for that dimension.
Error in render_blobs (line 642)
slicecdat = reshape(cm(round(w),:),[size(Z),3]);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in fmridisplay/addblobs (line 378)
[blobhan, cmaprange, mincolor, maxcolor] = render_blobs(currentmap, obj.montage{i}, obj.SPACE, varargin{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in region/montage (line 388)
o2 = addblobs(o2, obj(i), varargin{:}, 'wh_montages', i, 'noverbose');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in mediation_brain_results_report (line 85)
montage(a_regions_fdr, 'colormap', 'regioncenters');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I checked the dimensions of the image files: when following the tutorial, the mask (91 x 109 x 91) and mediator contrast image (47 x 56 x 31) are different to each other, but given the problem also exists in my data, where the dimensions of the functional images are the same as the mask (91 x 109 x 91), I wonder if it's really to do with that. I've tried a lot of things suggested through Chatgpt but it's gotten to a point where it seems the solution can't be this complicated and maybe I'm just missing something obvious.
Does anyone have any recommendations? I'd be ever so grateful.
Thanks!
Julia