dimension mismatch

조회 수: 5 (최근 30일)
FIR
FIR 2011년 10월 14일
I have a set of code ,for some RGB images my codes works but for some the coed not work i get an error "Subscripted assignment dimension mismatch",can u tell how to solve it
  댓글 수: 2
Wayne King
Wayne King 2011년 10월 14일
You need to give a simple example of the sizes of your inputs and what you are doing to produce the error.
FIR
FIR 2011년 10월 14일
size of image1=183 275 3
size of image2=238 174 3
size of image3= 72 72 3
I get error for 2nd and 3rd image but not for 1st image
i grt error in this line
trunCoarseImg(:,:,:) = coarseImg((n+1):(end-n),(n+1):(end-n));
egere n=6

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2011년 10월 14일
I already gave him the reason why in his original post: http://www.mathworks.com/matlabcentral/answers/18294-dimension-mismatch

추가 답변 (2개)

the cyclist
the cyclist 2011년 10월 14일
Breakpoint your code just before the line that causes the error. Then look at the sizes of the expressions on the left and right side of the assignment statement. You will likely find that they are not the same size, which is what causes that error message.
  댓글 수: 1
FIR
FIR 2011년 10월 15일
if this is the case as u said ,then y it works for one type of 3d image

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 10월 15일
The first time through, trunCoarseImg is not initialized.
When you use ':' as a subscript in the target of an assignment for an uninitialized array, MATLAB gives more flexibility and treats the ':' as meaning "as much as is needed". Each 2D array is also a 3D array with final dimension 1, so in this initialization case, MATLAB says "Okay, the third dimension only needed a range of 1" and permits the initialization.
There are other leeways that are permitted when assigning to a variable that is not initialized: for example, you can assign any data type.
But when a variable is already initialized, and it only a portion of the variable is marked as the destination, then the rules for assigning in to it are different. For example, the values being assigned must be of a data type that can be converted into the existing data type of the variable. You cannot, for example, assign a cell to an element of a numeric array.
One of the other differences when the destination array exists is that you are only permitted to use the the ':' index destination on a trailing singular dimension if the value being assigned is a scalar (and possibly if the source and destination are both column vectors: I would need to test that specific case.) Otherwise, the number of dimensions of the source value must be exactly the same as ndims of the target.
Arguments could be made about what should happen if ':' is used for a trailing singular dimension and the corresponding implicit dimension of the source is 1, but Mathworks choose to implement this as a "sanity check". Code that really needs this kind of functionality can be made to work with some thought and effort, but the situation represents erroneous coding so much of the time that the errors it prevents (by complaining) outweigh the cost of recoding for the few cases where a degenerate trailing dimension is a desirable possibility.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by