Matlab, "Assignment has more non-single rhs sizes than non-single indexes"

I am trying to create an RGB label fragment using label2rgb and use it to update the RGB volume, for example:

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

I get 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 the following:

 size(labelRGB_slice) ans = 160 216 3 K>> size(handles.labelRGB(:,:,handles.current_slice_z) ) ans = 160 216 

I declared handleles.labelRGB as follows:

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

Therefore, I do not understand the inequality of the index.

How can I complete the slice assignment?

+4
source share
1 answer

According to the way you declared handles.labelRGB , it is a 4D array of size [160 216 3 3] , but you index it as a 3D array with handles.labelRGB(:,:,handles.current_slice_z) , which means that 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 size matrix [160 216] . Therefore, depending on the value of handles.current_slice_z you need to either use

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

or

 handles.labelRGB(:,:,handles.current_slice_z,:) = labelRGB_slice; 
+5
source

Source: https://habr.com/ru/post/1498880/


All Articles