gpt4 book ai didi

Matlab, "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"

转载 作者:太空宇宙 更新时间:2023-11-03 19:42:44 28 4
gpt4 key购买 nike

我正在尝试使用 label2rgb 生成 RGB 标签切片并使用它来更新 RGB 体积,如下所示:

    labelRGB_slice=label2rgb(handles.label(:,:,handles.current_slice_z), 'jet', [0 0 0]);


handles.labelRGB(:,:,handles.current_slice_z) = labelRGB_slice;

我收到以下错误:

**Assignment has more non-singleton rhs dimensions than non-singleton subscripts**

Error in Tesis_GUI>drawSeedButton_Callback (line 468)
handles.labelRGB(:,:,handles.current_slice_z) = labelRGB_slice;

调试时我得到这个:

size(labelRGB_slice)

ans =

160 216 3

K>> size(handles.labelRGB(:,:,handles.current_slice_z) )

ans =

160 216

我这样声明 handles.labelRGB:

handles.labelRGB = zeros(dim(1), dim(2), dim(3), 3);

所以我不明白索引差异。

如何使切片分配工作?

最佳答案

根据您声明 handles.labelRGB 的方式,它是一个大小为 [160 216 3 3] 的 4D 数组,但是您将其索引为 3D 数组使用handles.labelRGB(:,:,handles.current_slice_z) 这意味着 matlab 将使用 linear indexing对于最后两个维度。因此,如果说 handles.current_slice_z = 5,它返回 handles.labelRGB(:,:,2,2),这是一个大小为 [160 216 的矩阵]。因此,根据 handles.current_slice_z 的含义,您需要使用

handles.labelRGB(:,:,:,handles.current_slice_z) = labelRGB_slice;

handles.labelRGB(:,:,handles.current_slice_z,:) = labelRGB_slice;

关于Matlab, "Assignment has more non-singleton rhs dimensions than non-singleton subscripts",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18435698/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com