How to solve "Subscripted assignment dimension mismatch"?

I have two images; imgA and imgB with the size of 43*54*3
I wanted them to display on my screen (1366*768)
I was using the below code to do the same, however it shows me an error say dimention mismatch( sometimes for imgA or imgB)
Please find below code
PS: n is number is trials. img final size is 1366*768
I am using 2016a
if disp_position(n) == 1
LorR{n}= 'Left up';
Img_final(279:322,548:602,:)=imgA;
Img_final(279:322,818:872,:)=imgB;
Img_final(447:490,548:602,:)=imgB;
Img_final(447:490,818:872,:)=imgB;
elseif disp_position(n) == 2
LorR{n}= 'Right Up';
Img_final(279:322,548:602,:)=imgB;
Img_final(279:322,818:872,:)=imgA;
Img_final(447:490,548:602,:)=imgB;
Img_final(447:490,818:872,:)=imgB;
elseif disp_position(n) == 3
LorR{n}= 'Left down';
Img_final(279:322,548:602,:)=imgB;
Img_final(279:322,818:872,:)=imgB;
Img_final(447:490,548:602,:)=imgA;
Img_final(447:490,818:872,:)=imgB;
else
LorR{n}= 'Right down';
Img_final(279:322,548:602,:)=imgB;
Img_final(279:322,818:872,:)=imgB;
Img_final(447:490,548:602,:)=imgB;
Img_final(447:490,818:872,:)=imgA;
end
Please help me solving this problem. I was trying to tackle this last one day but did not successed

2 件のコメント

Looky
Looky 2019 年 8 月 2 日
You made a little error with your indexing. The way it works in matlab is, that if you have
279 : 322
this means that the 279th element up to the 322th element (included) is used. (this is different then e.g. in python). As a consequence the number of elements here is 322 -279 +1 = 44 which is one element more than your images.
Just change either 279 to 280 or 322 to 321 and similar for the other indexes and the error should disappear.
Kurni Eswar
Kurni Eswar 2019 年 8 月 2 日
Thanks for the help
Error is disappered

サインインしてコメントする。

 採用された回答

Guillaume
Guillaume 2019 年 8 月 2 日

0 投票

Off by one error, 279:322 is 44 elements not 43. Same for all the other indices, you've got one more element than required.
Anyway, why aren't you using montage for this?

5 件のコメント

Kurni Eswar
Kurni Eswar 2019 年 8 月 2 日
Thanks for the reply. The error is still there even after the change it by one pixel
The change i did is from 279:322 to 279:321
I dont know the function name montage. Hence I did not use.
Kindly help me solving this error
Guillaume
Guillaume 2019 年 8 月 2 日
As I said, you'll have to change all the indexings, not just the 279:322. They're all off by one, so: 548:601, 447:489, and 818:871
Better, don't hardcode the end by use the actual image size:
[nrows, ncols, ~] = size(imgA)
img_Final(278 + (1:nrows), 547 + (1:ncols), :) = imgA;
img_Final(278 + (1:nrows), 817 + (1:ncols), :) = imgB;
%... etc
Guillaume
Guillaume 2019 年 8 月 2 日
編集済み: Guillaume 2019 年 8 月 2 日
While we're at it, whenever you're writing the same lines of code with only small variation, you should refactorise to remove the duplication. In this case:
%disp_position(n): indicates in which quadrant imgA is to be displayed
%constants that should be defined outside the loop:
labels = {'Left up', 'Right up', 'Left down', 'Right down'};
locations = [279, 548; 447, 548];
images = {imgA, imgB, imgB, imgB}; %build cell array of the 4 images
images = circshift(images, disp_position(n)-1); %rotate the array according to disp_position
LorR{n} = labels(disp_position(n)); %get label according to disp_position
[nrows, ncols, ~] = size(imgA);
Img_Final(locations(1, 1) + (0:nrows-1), locations(1, 2) + (0:nrows-1), :) = images{1};
Img_Final(locations(1, 1) + (0:nrows-1), locations(2, 2) + (0:nrows-1), :) = images{1};
Img_Final(locations(2, 1) + (0:nrows-1), locations(1, 2) + (0:nrows-1), :) = images{1};
Img_Final(locations(2, 1) + (0:nrows-1), locations(2, 2) + (0:nrows-1), :) = images{1};
No need for if...else, and if you ever want to change to location, only one line to edit, the locations line.
Kurni Eswar
Kurni Eswar 2019 年 8 月 27 日
Can someone help me writing a code similar to attached image file to fit my new data? Earlier I have written a code to do it. But somehow i lost it. please me
I have few number. The solid line with extenstion triangle to drawn till the values were given
The same for below polar plot as also but with dotted lines
The circles at the centre also to be drawn as per the values given
Please find the appended images for more details
Help me, this is very importance
My matlab version is 2016a
Walter Roberson
Walter Roberson 2019 年 8 月 27 日
編集済み: Walter Roberson 2019 年 8 月 27 日
Please create a new Question for that, Kurni Eswar.

サインインしてコメントする。

その他の回答 (2 件)

KSSV
KSSV 2019 年 8 月 2 日

0 投票

What the necessity to save those images into a bigger image? USe montage. Read about it.

1 件のコメント

Kurni Eswar
Kurni Eswar 2019 年 8 月 2 日
Hi. Thanks for the reply. I want them to display with perticular size at intended coordinates. Kidnly help me

サインインしてコメントする。

Walter Roberson
Walter Roberson 2019 年 8 月 2 日

0 投票

279:322 is 44 rows not 43
548:602 is 55 columns not 54
Consider that 2:6 would designate 2 3 4 5 6 for a total of 5 values, not (6-2=4) values. Count is last minus first plus 1, not last minus first.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2019 年 8 月 2 日

編集済み:

2019 年 8 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by