MATLAB Answers

Index exceeds matrix dimensions.

1 ビュー (過去 30 日間)
Mar
Mar 2018 年 11 月 28 日
回答済み: Guillaume 2018 年 11 月 28 日
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 日
"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.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by