Fill a nxm matrix with vectorised expression
显示 更早的评论
Hi all,
here my doubt: i have a matrix M with dimensions nxm. The matrix is initially initialised with zeros, and i fill each M(i,j) calling another function:
M = zeros(n,m)
for i = 1:n
for j = 1:m
M(i,j) = another_function(several_inputs);
end
end
is it possible to fill the matrix M without the for loops, but instead using a vectorised expression?
Thanks
4 个评论
Konstantin
2020-10-16
What is the condition for selecting the function? Is the function different for each cell of the matrix, or is it possible, that the same function will be used for several cells?
KSSV
2020-10-16
It depends on what your another_function is.
Andrea Agosti
2020-10-16
Konstantin
2020-10-16
sometimes it works to vectorize the function itself
matrix = another_function(matrix)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!