Is it possible to vectorize for only one input?
1 次查看(过去 30 天)
显示 更早的评论
Suppose there are two variables.
v1 = [1 2 3];
m1 = [1 2 3; 4 5 6];
I hope to create another matrix m2, having the same size with m1, and its (i, j) component is defined by
m2(i, j) = sum(v1 > m1(i, j))
In this case, clearly one solution is use "for" loop twice.
m2 = zeros(2, 3);
for i = 1:2
for j = 1:3
m2(i, j) = sum(v1 > m1(i, j));
end
end
However I want to know whether we can apply vectorization for the above procedure. To do this, I first thought that I may create an anonymous function
test_opr = @(v, x) sum(v > x);
and vectorize for the only latter input(while fixing v). But I couldn't find a proper way to do this. Is there any useful trick or alternative?
Thanks in advance.
0 个评论
采纳的回答
更多回答(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!