Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

matlab

I'm attempting to generate a RGB label slice using label2rgb and use it to update a RGB volume, like this:

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


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

I'm getting the following error:

**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;

When debugging I get this:

size(labelRGB_slice)

ans =

   160   216     3

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

ans =

   160   216

I declared handles.labelRGB like this:

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

So I don't understand the index disparity.

How can I make the slice assignment work?

like image 753
andandandand Avatar asked Aug 26 '13 02:08

andandandand


1 Answers

Based on the way you have declared handles.labelRGB it is a 4D array of size [160 216 3 3] however you are indexing it as a 3D array using handles.labelRGB(:,:,handles.current_slice_z) that means matlab will use linear indexing for the last two dimensions. So if, say handles.current_slice_z = 5, it returns handles.labelRGB(:,:,2,2) which is a matrix of size [160 216]. So depending on the meaning of handles.current_slice_z you either need to use

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

or

handles.labelRGB(:,:,handles.current_slice_z,:) = labelRGB_slice;
like image 60
Mohsen Nosratinia Avatar answered Nov 15 '22 03:11

Mohsen Nosratinia