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

2 ビュー (過去 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:

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by