Index exceeds matrix dimensions.

1 view (last 30 days)
Mar
Mar on 28 Nov 2018
Answered: Guillaume on 28 Nov 2018
Hi,
I have 4D data in a Nifti file format. My code looks like this:
vals = importdata('/Users/values.txt')
data = load_untouch_nii('/Users/Niftidata.nii');
data = bsxfun(@rdivide, data, data(:,:,:,find(vals==0)));
When I run those lines I get the following error but I don't understand why: Index exceeds matrix dimensions.

Answers (1)

Guillaume
Guillaume on 28 Nov 2018
"When I run those lines I get the following error but I don't understand why"
That would be because find(vals==0) returns one (or more) index that is greater than size(data, 4). There is nothing in your code that guarantees that it is not the case. As written, it is an implicit assumption of your code that the zeros of values.txt are at indices smaller than the size of that 4th dimension in your nifti file. Obviously, for the two files you're using, this is not the case. There's nothing we can do about that. Either use files where the implicit assumption is true or change what you are doing with these files.

Tags

Community Treasure Hunt

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

Start Hunting!