how to read\scan all data of a row present in an array and pick data according to their priority number which is placed in next column of that particular row?
1 次查看(过去 30 天)
显示 更早的评论
hi... i have an array which has 5 rows and in second coulmn I placed their priority (1 to 10) higher number means higher priority now i have an another array in which I want to place these arrays according to their priority.
for example: A[ 1.2160 7
0.8931 10
-0.8498 2
1.6598 6
0.3412 9]
B [ 0.310 7
0.2080 2
0.0466 1
0.7997 4
0.8229 5]
A is an array in which each data has their own priority between 1 to 10. Now how I find out the data with higher priority and put that specific value in array B by replacing the value present in that array that has LRU value less than 7 in sequence ( for example from array B first data with lru number 1 is evicted first and from array [A] data with priority 10 replaced it , then data with lru 2 is evicited and from array A anotther data replace it with higher priority , then data with lru 3 if any data has till 7. data with lru 7 is not replaceable ). I only want to place that specifice data in another array not their priority number.
result array should be Resulting array [ 0.310
0.3412
0.8931
1.2160
1.6598 ]
basically data with priority 10 replace data of array B with lru 1, data with priority 9 replace data of array B with lru 2, data with priority 7 replace data of array B with lru 4 data with priority 6 replace data of array B with lru 5... data of array with lru 7 remains on its position becuase it has lru 7
how can I do this in a sequence with loop when i have a large amount of data then how to do it ? please any one help me out .
how to do the same process with arrays with different dimesions? fro example if A has 20 rows of data with their priority and array B has 5rowsof data with their lru. then how to replace data from array A according to their priority with data in array B with less lru?
0 个评论
采纳的回答
Askic V
2023-2-20
编辑:Askic V
2023-2-20
Hello Saira,
for this particular case, asumming that priorities go between 1 and 10, this code can work:
A = [1.2160, 7;
0.8931, 10
-0.8498, 2;
1.6598, 6;
0.3412, 9];
B = [0.310, 7;
0.2080, 2;
0.0466, 1;
0.7997, 4;
0.8229, 5];
for i = 1: size(B,1)
if B(i,2) < 6
ind = 11 - B(i,2);
B(i,1) = max(A(A(:,2) == ind));
end
end
result_arr = B(:,1)
This code will modify B as you explained in the description, but since only an array is expected, then the first column of modified B is extracted. If you want to know why 11 and 6, think about max priority and 1/2 of the range.
Anyway, I think you'll have little trouble or not trouble at all to modify this code to suit your actual needs.
3 个评论
Askic V
2023-2-28
Please post more realistic matrices A and B and the expected outcome. Then it will be easier to see what needs to be modified in the existing code.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!