Allocation of values to a matrix under a specific condition

2 views (last 30 days)
Hi everyone,
Let us assum Matrix A as follows:
A = [0 0 0 1 1 0 0 0
0 2 2 0 0 0 0 3
0 0 0 0 0 0 0 0]
I have to allocate an array including two fours ([4 4]) to the first two rows of Matrix A (allocation of values to the matrix is possible only where elements of the matrix are equal to zero).
If columns 2-4 are the desirable places for the allocation of the array, allocaiton preferences are sorted below based on their priority (prefrence 1 has greater priority):
  1. Ideally, I prefer to allocate [4 4] to a place in the range (i.e., columns 2-4). However, violation from the range is possible (less violation is better).
  2. If allocation of the array was possible to both before and after the beginning of the desirable range (i.e., column 2) with equal violation from the range, it is better to allocate the array before the beginning of the range.
  3. If allocation of the array was only possible to after the beginning of the range, it is prefereable to place it closer to the beginning of the range.
Note that the range of allocation must be identical for all rows. Having said that, the solution to this question will be as follows:
A = [0 0 0 1 1 4 4 0
0 2 2 0 0 4 4 3
0 0 0 0 0 0 0 0]
Let us see another example. Matrix A is as follows:
A = [0 0 0 0 1 1 1 0 0 0 0 0
0 0 0 0 0 2 2 2 2 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0]
if the array is [3 3 3], the prefereable range is columns 4-8, and the allocaiton rows are 1, 2 and 3, the solution will be as follows:
A = [0 3 3 3 1 1 0 0 0 0 0 0
0 3 3 3 0 2 2 0 0 0 0 0
0 3 3 3 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0]
Note that allocaiton of the array to after the beginning of the desirable range would create an equal violation from the range, but it is preferable to assign the array to before the range (based on preference 2).
Would you please share you opinion on what is the fastest way to address this problem? I know it is complicated, so, if you need more clarificaiton, pelase do not hesitate to ask.
Thanks in advance,
Amir

Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!