How to solve "Subscripted assignment dimension mismatch"?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kurni Eswar
am 2 Aug. 2019
Bearbeitet: Walter Roberson
am 27 Aug. 2019
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 Kommentare
Looky
am 2 Aug. 2019
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.
Akzeptierte Antwort
Guillaume
am 2 Aug. 2019
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.
5 Kommentare
Walter Roberson
am 27 Aug. 2019
Bearbeitet: Walter Roberson
am 27 Aug. 2019
Please create a new Question for that, Kurni Eswar.
Weitere Antworten (2)
KSSV
am 2 Aug. 2019
What the necessity to save those images into a bigger image? USe montage. Read about it.
Walter Roberson
am 2 Aug. 2019
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!