Error: Index exceeds matrix dimensions

Hi,
I am trying to open a .mat correlation file (I'm a neuroimaging researcher), which contains 160x160 functional connectivity matrices. I am trying to load it into my script so that I can pick 11 regions of interest set as variable 'd', from the 160x160 matrix. However, when I try to run my code, it comes back as error 'index exceeds matrix dimensions'. Any ideas on how to solve this would be greatly appreciated. Thanks!
%Begin by defining variables%
ROICorrelation = ('ROICorrelation_0010028.mat'); % Define path
%ROI1 = % VMPFC
%ROI4 = % mPFC
%ROI6 = % vmPFC
%ROI7 = % vmPFC
%ROI11 = % vmPFC
%ROI14 = % ACC
%ROI17 = % sup-frontal
%ROI73 = %post-cingulate
%ROI85 = %precuneus
%ROI117 = %angular gyrus
%ROI136 = % occipital
d = [1,4,6,7,11,14,17,73,85,117,136]; % Define Default Mode ROIs as 'd'
x = ROICorrelation(d,d); % Run correlation analyses (i.e. ROI x ROI pairs) for DMN ROIs in a new matrix 'x'
_____________________________________________________________
Index exceeds matrix dimensions.
Error in subj0010028 (line 26)
x = ROICorrelation(d,d); % Run correlation analyses (i.e. ROI x ROI pairs) for DMN ROIs in a new matrix 'x'

Answers (1)

ROICorrelation = ('ROICorrelation_0010028.mat')
defines ROICorrelation to be a character vector that happens to contain 26 characters.
x = ROICorrelation(d,d)
attempts to access a variety of positions in that character vector, including (1,1), (1,4), ... (1,136), (4,1), (4,4), ... (4, 136), right up to (136,117) and (136,136). Those positions mostly do not exist in the character vector.
Perhaps you wanted to load() some data from the .mat file -- but even if so then it seems odd that you would happen to want that wide a combination of positions. And if ROICorrelation is expected to be data loaded from the file named earlier, then that does not agree with "Run correlation analyses", which sounds like ROICorrelation is intended to be a function.

7 Comments

All I'm trying to do is select those 11 regions of interest from the 160x160 matrix. I see your point, but I don't know how to modify the code in order to do so. If it can't search a matrices with that many characters as you say, then how else do I pick those 11 data points?
You do not have a 160 x 160 matrix at this point: you have a character vector (length 26). You probably need to load() something from the file name designated by the character vector. That would probably give you the 160 x 160 matrix you want.
After that, it is not clear what is necessary to select "regions of interest". Possibly what you have already is what you need. Possibly what you need is ROICorrelation(d,:) or ROICorrelation(:,d) . What size of output are you expecting?
I should, at the end, have an 11x11 matrix (from the d,d function), and a 160x160 matrix (from the ROIcorrelation variable). I'm new to this syntax, so apologies if things aren't clear. I don't know what else to load, since all I have is the ROICorrelation_0010028.mat file. When I double click on it and load it, it shows 160x160 under 'workspace', which confused me. I thought that it should automatically load as a 160x160 matrix, but I guess not.
*edit: I tried your syntax; it still didn't work after trying ROIcorrelation (:,d)
ROICorrelation_file = 'ROICorrelation_0010028.mat';
datastruct = load(ROICorrelation_file);
fn = fieldnames(datastruct);
ROICorrelation = datastruct.(fn{1}); %load first variable from .mat whatever the name of it is
d = [1,4,6,7,11,14,17,73,85,117,136]; % Define Default Mode ROIs as 'd'
x = ROICorrelation(d,d); % Run correlation analyses (i.e. ROI x ROI pairs) for DMN ROIs in a new matrix 'x'
It says
Argument to dynamic structure reference must evaluate to a valid field name.
Unless the matrices were created by a third party code that violated the rules about valid variable names (uncommon but not unheard of), the single most likely possibility is that your .mat files are not binary MATLAB files and are instead badly named text files.
Never mind, we figured it out. It was another line that had to be added; not related to what we spoke about above. Thanks for your help!

Sign in to comment.

Categories

Asked:

on 23 Feb 2018

Commented:

on 23 Feb 2018

Community Treasure Hunt

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

Start Hunting!