Unable to perform assignment because the left and right sides have a different number of elements.

조회 수: 1(최근 30일)
I am attempting to swap the pixels of the brightest with the darkest in the image. I get this error but as far as I know they have the same number of elements. I check with numel.
  댓글 수: 1
Jan
Jan 2022년 11월 19일
If you post code as formatted text, it can be used to create an answer using copy&paste. Screenshots are less useful.

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

답변(2개)

the cyclist
the cyclist 2022년 11월 19일
The assignment will only have the same number of elements if maskMax3D and maskMin3D have the same number of TRUE elements. For example, with smaller matrices, so that we can see what is going on:
% Note that these masks do not have the same number of TRUE elements
mask1 = logical([1 1; 1 0]);
mask2 = logical([1 0; 0 1]);
M1 = [2 3; 5 7];
M2 = [11 13; 17 19];
% Therefore these two arrays do not have the same number of elements, and
% cannot be assigned to each other
M1(mask1)
ans = 3×1
2 5 3
M2(mask2)
ans = 2×1
11 19

Image Analyst
Image Analyst 2022년 11월 24일
Not sure what you mean because your question is not complete (no code, no images, no good explanation). Maybe it's this
yourImage = 255 - yourImage;
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

태그

Community Treasure Hunt

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

Start Hunting!

Translated by