Choose a cell array that satisfy better some criteria
Show older comments
Given two arrays
A = [45 41 19 32 32 15 24 1 41 15 15 15 15];
B = [200 200 200 200 200 200 200 200 200 200 200 200 200];
I want to make the difference, substracting A from B and obtaining
C = [155 159 181 168 168 185 176 199 159 185 185 185 185];
Now I want to ordinate the cloumns of C and obtain a vector with column number from higher value to loerr one. Note for example that the highest value is 199, so column 8. then we have 185 so 6, 10, 11, 12,13 . At the end we will have an array we all the columns number from higher value to lower one
D = [8 6 10 11 12 13 3 7 4 5 2 9 1];
Now I want to create a vector from D that I will use to make comparison with other arrays. In particular I give weigth from 13 to 1, at all the values in D, creating E
E = [13 12 11 10 9 8 7 6 5 4 3 2 1];
Where 13 refers to element 8, 12 to element 6, 11 to element 10 and so on.
From array E we derive the number 13121110987654321, that we will use for comparison we other vector.
Now we have a cell array
VM = {[46 41 24 33 32 15 41 19 0 13 15 14 15]; [0 2 41 10 9 32 9 32 41 31 31 31 31];[13 10 19 3 2 41 0 20 41 41 41 41 41]}
For each cell of VM I want to do same, taking for example the first cell
VM{1,1}= [46 41 24 33 32 15 41 19 0 13 15 14 15];
I want to do thefollowing and ordinate the column from the higher to lower obttaining
F=[1 2 7 4 5 3 8 6 11 13 12 10 9]
As we can see the highest value is 46 so I put one in front. then 41 so I put 2.
Then I have to make comparison between F and E. for each element of F I wan to report how many values has that element in front of it in E. So for example, taking the first element of F: 1.
1 in E has 0 element in front of it. so I create a new vector G with 0 in front. element 2 has 2 element in front of it so I put 2. 7 has 6 element. 4 has 3 and so on
G = [0 1 6 3 4 2 7 5 10 12 11 9 9]
the array G give as a result the number 163427510121199, later we will compare this number with the one obtained in E.
Taking now the second cell
VM{1,2} = [0 2 41 10 9 32 9 32 41 31 31 31 31];
I obtain again
F = [3 9 6 8 10 11 12 13 4 5 7 2 1];
again
G = [2 8 5 7 9 10 11 12 3 4 6 1 0];
In this case we obtain a number 2857910111234610
The number obtained in each cell of VM has to be reported in a vector and
BB= [163427510121199, 2857910111234610, ...] and made a comparison with the one obtained from E: 13121110987654321.
As expected the one in E is the highest one. Now we want to give a weight to the one obtained in BB. Remember that the higher the better. the hogher value in BB will have a value of 200 (fixed) then going down to the ohter I want a value every time reduced by 3. so 200, 197, 194 and so on.
In thi case from BB we will have
HH = [197, 200 , ..].
So the main Idea is evertime to select the cell array in VM that summed to inital vector A, allow us to enhance the A quantity following the values in B, without producing more in one column with respect to the others.
SIMPLER SOLUTION ARE WELL ACCEPTED
May someone help me with the code?
14 Comments
Bob Thompson
on 11 Oct 2019
1) Do you have any of the code written so far? If so, please post it here.
2) Why are you weighing D from highest to lowest with 13 - 1, but then F gets weighed from highest to lowest with 1 - 13? Also, if VM{1,1}(9) = 0, why is F(9) not 13?
3) I'm not entirely sure how you are creating G. It looks like you are just doing F(:)-1 (except for the last element; is that a typo?)
4) During VM{1,2} you create F and E. Is that supposed to be F and G? It look like the E being created here is the same process as the previous G.
5) What is the point of all this? There may be a simpler solution, but I don't understand the greater purpose of what you're trying to accomplish.
luca
on 11 Oct 2019
luca
on 11 Oct 2019
luca
on 11 Oct 2019
Bob Thompson
on 11 Oct 2019
FYI, matlab convention calls an 'element' as a single piece of data within an array, which has an address defined by a row, column, sheet, etc. For example, VM{1}(1,1) is an element of VM which is found in the first row, '(1,' and first colum, '1),' of the first cell '{1}' of the VM cell array. I will be using that naming convention from now on.
2) My understanding is that D and F are the indices corresponding to the appropriate descending order position of the elements of C and VM. D and F do not contain the actual values that these indices correspond to, merely their position within the heirarchy. As such, I understand how these two can be related, but I am not sure how E relates to the issue. As far as I'm concerned, E is literally just a descending order array from 13 -> 1 which will be constant, independant of the order of D, F, or any other array.
3) From what you have described, G will always be F - 1. This is because a) E is always a descending order of integers from 13 -> 1, and b) you are not asking about the value of the element of E, just the position, which will not change. Are you sure you don't want to compare the values of F and D, and determine the difference in positions there?
5) This is going to be my main point to come back to. I think I understand a little bit better what you're trying to do. You want to get C, because it is the difference in number of elements for each column. You want to compare A and VM to determine which ones are closest. I am still confused as to what the purpose of this comparison is though. Are you just trying to find which row of VM is closest in size to A? I would like to help as much as I can, and while I can just write some code that does the steps you have asked, if I can get a picture from a step further back we might be able to get a much more concise method written out for you.
Bob Thompson
on 11 Oct 2019
Hmm, ok, I'm getting a better picture of what you're trying to do.
What is the purpose of looking at, and comparing the different locations of the numbers? Why wouldn't you just look at the values (because you're trying to ultimately compare to B, which is value based)?
luca
on 11 Oct 2019
Bob Thompson
on 11 Oct 2019
In A and B you have values, which you are comparing to find the differences. Every other array, except VM, contains position information, rather than the direct data numbers.
As for comparing position information with more than 9 numbers, I recommend doing a direct element comparison, rather than a concatonated comparison. Just use some logic setup.
check = find(A==VM{1});
The value of check will then be the elements of A, or VM{1}, that match each other.
luca
on 11 Oct 2019
Bob Thompson
on 11 Oct 2019
Edited: Bob Thompson
on 11 Oct 2019
Mmm, ok, I think I see what you mean. Let me think about it over the weekend. I will get back to you if nobody else responds by then. Sorry for not having a more prompt solution.
luca
on 11 Oct 2019
luca
on 14 Oct 2019
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!