Matrix manipulation in three numbers
1 次查看(过去 30 天)
显示 更早的评论
Hello
Please I have 2 numbers in a column that does the same function below
croppedz = z(1:end-mod(end, 2*K), :); %ensure that height of J is a multiple of 2*K by removing extra elements from the end
result = zeros(size(croppedz, 1) / 2 / K, size(croppedz, 2)); %preallocate result
for col = 1:size(croppedz, 2) %loop over the columns. You can't do this without a loop due to the requirement to sort each columns separately
result(:, col) = sum(reshape(sort(croppedz(1:2:end, col)), K, []), 1) ./ sum(reshape(sort(croppedz(2:2:end, col)), K, []), 1); %sort even/odd rows, reshape each into a Kx? matrix, sum across rows and divide the two sums
end
I want to make it 3 numbers instead of two numbers various K as mentioned above for 2 numbers
Kindly get back
Regards
Tino
2 个评论
James Tursa
2019-5-22
(Tino's Answer moved here)
Thanks Walter
for instance I have the following matrices
1 C1
2 C2
2 C1
3 C2
4 C1
5 C2
3 C1
. .
. .
n C3
a matrix that can sort the numbers from lowest to highest and divide from the lowest first three numbers
Lower for k = 3 after sorting
K = C1 + C1+ C1/ C2 + C2 + C2
then down the sorted below when the list is not divisible by 3 it stops at the last number
Hope this is clearer
Tino
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!