Index in position 1 exceeds array bounds (must not exceed 64)
3 次查看(过去 30 天)
显示 更早的评论
I am plotting 4 different thresholded t-maps using .nii files. My first three t-maps are executed correctly. But there seems to be a problem with my fourth. Meaning that using the same script (and functions) works 3 out of 4 times. I attached error below. Matlab R2018a.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/473357/image.png)
function Y_rgb = sd_slice_to_rgb(Y, layer, settings)
% Panel dimensions
pandims = settings.slice.pandims;
% Use slover to scale slice to color map indices
Y_map_i = pr_scaletocmap(Y, ...
layer.color.range(1), ...
layer.color.range(2), ...
layer.color.map, ...
[0 256 0]);
% Convert to RGB - Error in next line
Y_rgb = reshape(layer.color.map(Y_map_i(:),:), ...
pandims);
Y_rgb(Y_rgb > 1) = 1;
end
% sd_display (line 93)
Y_rgb = sd_slice_to_rgb(Y_c,layers(i_layer),settings);
2 个评论
Walter Roberson
2020-12-29
Some element of Y_map_i is greater than 64 but layer.color.map only has 64 elements.
We do not know anything about pr_scaletocmap to know how that could come about.
回答(1 个)
Walter Roberson
2020-12-29
[0 256 0]);
The 256 there instructs that any values that would map outside of the colormap length should be replaced with 256, no matter what the length of the colormap is. You have at least one value that maps to outside the colormap, such as if your layer.color.range values are not correct for Y
2 个评论
Walter Roberson
2020-12-29
Put a breakpoint at
outvals = {img<1, img>cml, isnan(img)};
and execute the code. When it gets to the breakpoint, step one line so that outvals is assigned to. Now ask
nnz(outvals{2})
if the reported number is not zero then
img(outvals{i}) = lrn(i);
is going to have an meaningful effect.
When that happens, you need to examine
max(inpimg(:))
min(inpimg(:))
mx
mn
max(img(:))
cml
[BR, BC] = find(inpimg > mx, 1);
if ~isempty(BR)
fprintf('inpimg(%d,%d) = %g which is greater than the declared max, %g\n', BR, BC, inpimg(BR,BC), mx)
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Purple 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!