Index exceeds matrix dimensions.

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.

回答(1 个)

Guillaume
Guillaume 2018-11-28

0 个投票

"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.

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

标签

提问:

Mar
2018-11-28

回答:

2018-11-28

Community Treasure Hunt

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

Start Hunting!

Translated by