Superimposing a matrix of zeroes around a matrix of random values
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey,
I'm generating two matrices, where one is a randomized matrix of values between min and max (both varaibles in this case) and the other is a matrix of zeroes that is larger than the randomized matrix. When the matrix is randomized, it is 1 by 40,000. I use a for loop to develop it into a 200 by 200 matrix. Then, I want to use the img to create an image of this matrix as indictated in the code below. How would i go about superimposing the matrices on top of each other while still producing this image?
x = min+rand(1,40000)*(max-min);
y = zeros(300);
t = (sum(x)/(40000));
for ix = 1:200
for iy = 1:200
icount = icount +1;
img(ix,iy) = eis(icount);
end
end
figure
imagesc(img);
colorbar;
contrast(img);
colormap gray
0 commentaires
Réponses (1)
Deepak
le 9 Déc 2024
To superimpose a smaller randomized matrix onto a larger zero matrix and produce an image, first reshape the 1x40,000 randomized matrix into a 200x200 matrix.
Create a larger 300x300 zero matrix. Choose a starting position within the larger matrix to place the smaller one, ensuring it fits within bounds. Assign the smaller matrix to this section of the larger matrix using appropriate indexing.
Finally, use “imagesc” to visualize the combined matrix and apply a grayscale colormap for contrast.
Below is a sample MATLAB code to achieve the same:
min_val = 0; % Define min value
max_val = 1; % Define max value
% Generate the randomized matrix and reshape it
x = min_val + rand(1, 40000) * (max_val - min_val);
img = reshape(x, 200, 200);
% Create the larger matrix of zeroes
y = zeros(300);
% Superimpose the 200x200 matrix onto the 300x300 matrix
% Choose the top-left corner of the 200x200 matrix within the 300x300 matrix
start_row = 51; % Example starting point (to center the 200x200 matrix)
start_col = 51;
% Place img into y
y(start_row:start_row+199, start_col:start_col+199) = img;
figure;
imagesc(y);
colorbar;
colormap gray;
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!