Simultaneously Calculating Function from matrix of variables

Hello there! I have variables in matrix D, there are 5 columns in each row and the column has values for 5 variables. I am using the following codes for calculation.
for jj=1:1:size(D(:,1))
mete(jj)=fobj(D(jj,:));
end
In this code, fobj is running a function file by using the lines of matrix D. But it takes longer time to calculate than I want when I increased the size of the matrix. I would like to use these variables not line by line but I need to use them as matrix. how could I calculate the function values for all the lines of variables in a very short time as a matrix instead of using "for loop"?

5 Commenti

any possibility to have fobj? If possible, it could be just a matter of vectorization
function o = F1(x)
o=sum(x.^2);
end
This is the function
Wouldn't that function work just as well for 2D as it does for a 1D vector? If all you're doing is squaring the individual elements, it shouldn't matter if you feed it one element, one line, one sheet, or any size matrix. It should be able to perform the function no matter how much you pass into it.
I actually work with test functions. I am trying to speed up a process. The process consists of a matrix of variables (size=24300000x5). There are 5 variables and one column for each variables. I have to use these variables in test functions. I would like to calculate the test fucntion for all rows of the matrix simultaneously. Could you please help me from your experiences.
Being able to vectorize an operation (which allows you to evaluate all at once instead of in a for loop) is dependant on the operation you're trying to perform. Your example showed that you were doing a squaring operation, which is already set up to be vectorized, so you don't need to have your for loop at all for that example.
If the example is not your actual operation, then we will need you to post it to determine if it can be vectorized or not.

Accedi per commentare.

Risposte (0)

Categorie

Richiesto:

il 14 Ott 2019

Commentato:

il 16 Ott 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by