calculate values from different matrices
1 次查看(过去 30 天)
显示 更早的评论
I have a matrix U (n*v). I want for every column to have a matrix that has the number of the non-zero rows. For example U= [1 1 0; 2 0 2; 4 3 0; 4 0 0; 0 5 1; 3 1 3; 1 0 5; 0 2 1] will return for v1=1 [1 2 3 4 6 7], v2=2 [1 3 5 6 8], v3=3 [2 5 6 7 8]. Then, we have another matrix K (n*n) and we want for every new matrix we created before(v1 v2 v3) , to take the 5 nearest to zero values. for example [0.1 0.5 0.2 0.25 0.3 -0.1 0.4 0.35; 0.3 0.3 0.2 0.25 0.3 -0.1 0.4 0.35; 0.15 0.5 0.4 0.25 0.3 -0.1 0.4 0.35; -0.4 0.5 0.2 0.6 0.3 -0.1 0.4 0.35; 0.3 0.5 0.2 0.25 0.12 -0.1 0.4 0.35; 0.15 0.5 0.2 0.25 0.3 -0.1 0.4 0.35; 0.3 0.5 0.2 0.25 0.3 -0.1 0.213 0.35; 0.125 0.5 0.2 0.25 0.3 -0.1 0.4 0.12]
for row 1 is [1 3 4 6 7]
then, we want to create a new matrix A where every element is the sum of each absolute value of K multiplied with the respective values of U, and the sum will be divided by the sum of the 5 absolute values from K. For example: A(1,1)= {1*0.1+4*0.2+4*0.25+3*|-0.1|+1*0.4}/(0.1+0.2+0.25+|-0.1|+0.4)
0 个评论
采纳的回答
Roger Wohlwend
2014-5-28
Task 1:
m = size(U,2);
v = cell(m,1);
for k = 1 : m
v{k} = find(U(:,k) > 0);
end
Task 2: I don't understand what you want to do. v1, v2 and v3 are vectors of different lengths. How do you use them on the matrix K?
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!