¿how create sub-matrix with random numbers centered in the middle of the submatrix?

1 view (last 30 days)
Boys This is a problem that has me very confused and do not know how to solve it ..... is that I have a say matris A[1500, 20] and of each column choose to say a random value a(100.1), a(1000.2), a(1455.3), a(1234.4). .... and so on until column 20, and I create sub matrix should have 2 * Z +1 rows and 20 columns Z can be any natural number example 5 then my submatrix would have 2 * 5 +1 = 11 rows now the chosen values should be at the center of the rows of this submatrix and besides the before and after values, I leave an example of how it should be the submatrix:
1----- a(95,1) a(995,2) a(1450,3).........
2----- a(96,1) a(996,2)............................
3----- a(97,1) a(997,2) a(1452,3) a(1231,4).................a(xx-3,20)
4----- a(98,1) a(998,2) a(1453,3) a(1232,4) ................a(xx-2,20)
5----- a(99,1) a(999,2) a(1454,3) a(1233,4) ................a(xx-1,20)
6----- a(100,1) a(1000,2) a(1455,3) a(1234,4) .................a(xx,20)
7----- a(101,1) a(1001,2) a(1456,3) a(1235,4)..................a(xx+1,20)
8----- a(102,1) a(1002,2) a(1457,3) a(1236,4)..................a(xx+2,20)
9 ---- a(103,1) a(1003,2) a(1458,3) a(1237,4)..................a(xx+3,20)
10---
11--- a(105,1) a(1005,2) a(1460,3)
Uffff .......... get tired of writing,,,,,,, I think I understand the idea, with pencil and paper is easy but not as matlab????? To thank all help

Answers (1)

Image Analyst
Image Analyst on 3 Apr 2014
Try this:
clc;
workspace;
rows = 60; % Total number of rows in the matrix.
columns = 60; % Total number of columns in the matrix.
m=zeros(rows, columns); % Initialize with all zeros.
z = 2
numberOfRows = 2*z+1
numberOfColumns = 20
% Get random starting point.
topRow = randi(rows - numberOfRows+1, 1)
leftColumn = randi(columns - numberOfColumns+1, 1)
% Make up array with value 5 to paste in at the random location
mPaste = 5 * ones(numberOfRows, numberOfColumns);
% Paste it in
m(topRow:topRow+numberOfRows-1, leftColumn:leftColumn + numberOfColumns-1) = mPaste;

Community Treasure Hunt

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

Start Hunting!