changing a matrix size
Mostra commenti meno recenti
Hello,
Basically i want to change a logical matrix size from 144x144 to 512x512, here is the case that i have:
i have two images of the same object with those sizes accordingly with some region of interest approximately in the middle of the 144 image here is a small example:
the matrix of the region is as follows:
[0000000000
0001111000
0000110000
0000000000]
the regions are hazardous but in the middle give or take, i have them all. now i want to apply those regions to the bigger image so i need to expande the matrix to go with the 512x512 image. as follows
[000000000000000000000
000000111111110000000
000000001111000000000
000000000000000000000]
any ideas ?
Regards
4 Commenti
Steven Lord
il 6 Set 2019
If 512 was an integer multiple of 144 I would suggest repelem but it's not. So I think we're going to need to know more about what you intend "expande[sic] the matrix" to mean in this context to be able to offer useful suggestions. Let's take a smaller concrete example.
smallPattern = [0 0 0 1; 0 1 1 0; 0 0 1 0; 1 0 0 0]
If you wanted to expand smallPattern from a 4-by-4 matrix to a 10-by-10 matrix named largePattern, what exactly would largePattern contain and why? Please be as specific as possible.
abdelillah douhi
il 6 Set 2019
Modificato: abdelillah douhi
il 6 Set 2019
Bruno Luong
il 6 Set 2019
What you plot are not logical matrix.
Steven Lord
il 6 Set 2019
I hope you do get the idea now
No, I don't. There are many different ways you could expand a 144-by-144 matrix to be a 512-by-512 matrix. I asked what method you want to use. To make this a bit more concrete, using my 4-by-4 example above:
smallPattern = [0 0 0 1; 0 1 1 0; 0 0 1 0; 1 0 0 0]
Should it be expanded to 10-by-10 by padding?
larger = zeros(10);
% Pad along the bottom and right
largePattern1 = larger; largePattern1(1:4, 1:4) = smallPattern
% Pad along the top and right
largePattern2 = larger; largePattern2(7:10, 1:4) = smallPattern
% Pad on all four sides
largePattern3 = larger; largePattern3(4:7, 4:7) = smallPattern
Should we replicate the rows and columns?
% Each element is roughly equal in size, extra rows go to the
% left and top sections
largePattern4 = repelem(smallPattern, [3 2 3 2], [3 2 3 2])
% Shows some symmetry
largePattern5 = repelem(smallPattern, [2 3 3 2], [3 2 2 3])
Should we replicate the matrix as a whole then trim off the extra pieces?
twelve = repmat(smallPattern, 3);
% Trim the bottom and right
largePattern6 = twelve(1:10, 1:10)
% Trim the border on all four sides
largePattern7 = twelve(2:11, 2:11)
% Trim the top and left
largePattern8 = twelve(3:12, 3:12)
Each of those eight larger patterns is a different matrix, built in some way from the small pattern, and all are 10-by-10.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


