how to fill a matrix of size 180 * 180 by results obtained by another program knowing that I will go through the matrix in a way 4 * 4 example
The first box must be filled by 3 values of 1 and a 0 by the following four boxes by 2 values of 1 and two values of 0, the following four values a value of 1 and a value of 0, and so on. at the end of the matrix 180 * 180
note: the number of values of 1 and 0 is the output of another program and it is the program entry that I am developing it
Resulat=[1,0,1,1,0.0,.........
1,1,0,0.0.1,..........]

4 Comments

A = rand(4)>=0.5 ;
how do I do with a matrix size 180 * 180 and thanks in advance
thank you for you KSSV

Sign in to comment.

 Accepted Answer

Well you could use blockproc() to march along the data one element at a time and replacing the output block with the number of zeros specified in the input block in random locations. This requires the Image Processing Toolbox. Essentially it's
outputMatrix = blockproc(outputMatrix,[windowSize windowSize], myFilterHandle)
A full demo is attached.
0000 Screenshot.png
A =
4 2 1 4 1
4 4 4 2 4
1 3 3 4 2
1 4 4 4 2
outputMatrix =
1 1 1 1 0 0 1 1 0 0
1 1 0 0 0 1 1 1 0 1
1 1 1 1 1 1 0 1 1 1
1 1 1 1 1 1 1 0 1 1
1 0 1 1 1 1 1 1 1 1
0 0 1 0 0 1 1 1 0 0
0 0 1 1 1 1 1 1 0 1
1 0 1 1 1 1 1 1 1 0
Note how each 2x2 block of the output array has as many 1's in it as the corresponding number in the input array A.

6 Comments

I tried with this matrix (attached) but still the same problem
Looks like it worked to me. Code is attached and figure is below. Exactly why do you say you have any problem. Is it because you said "I have an array of size 95 * 95 pixel each pixel contains a value either (1 or 2 or 3 or 4)" when your array actually has values 0,1, 2, and 3? My code doesn't care. It will work regardless as long as the numbers are less than the number of elements in the block. So what's the problem?
0000 Screenshot.png
Dakhli's "Answer" moved here:
thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu so much
dakhli mohamed
dakhli mohamed on 28 Dec 2018
Edited: Image Analyst on 28 Dec 2018
Thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu so much
Can I ask you another question please?
I want to save the result matrix in a variable so that I use it later.
How do I do that?
It already IS saved in a variable called outputMatrix.
If you want to store it to a file on disk that another program can read in, you can use save():
fileName = fullfile(pwd, 'outputMatrix.mat')
save(fileName, 'outputMatrix');
then, in the other program use load():
s = load(fileName);
outputMatrix = s.outputMatrix;
thank you so much

Sign in to comment.

More Answers (1)

Omer Yasin Birey
Omer Yasin Birey on 28 Dec 2018
Edited: Omer Yasin Birey on 28 Dec 2018
Hi dahkli, try this
result = eye(180);
for i = 1:numel(result)
temp = rand>(0.25*mod(i,3));
result(i) = temp;
end

2 Comments

I have an array of size 95 * 95 pixel each pixel contains a value either (1 or 2 or 3 or 4)
I will eventually create another size array (190 * 190)
if the pixel contains a value of 1 so the four subpixel new array containing a 1 and 3 zeros
if the pixel contains a value of 2 so the new array contains 2 valeues of 1 and 2 values of 0
if the pixel contains the value 3 so the new array contains 3 value of 1 and a value of 0
if the pixel contains the value 4 so the new tab contains 4 values of 1 and zeros value of 0
exempl:
A=[1,3
2.4]
Result new array=[1.0 1,1
0,0 1,0
1.0 1,1
1,0 1,1]
the four sub-pixel to the left of the second array represents the first array pixel (A)
and in my ca the table A is of size 95 * 95
Help please !!!!!!!
thank you for you Omer Yasin Birey

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!