Script optimization: for loop, if statement, large dataset
Mostra commenti meno recenti
Hello everyone,
below is the part of my script that I would like to be optimized. Any tips would be greatly appreciated.
Note: A = [1200x1200]
Pm = 0.2
N = length(A);
for Node_i = 1: N
if(Int(Node_i) > 0) && (rand <= Pm)
k_Node_i_in = 0;
k_Node_i_out = 0;
for Node_j = 1 : N
if(Node_i ~= Node_j) && (Child.CID(Node_j) == Child.CID(Node_i))
k_Node_i_in = k_Node_i_in + A(Node_i, Node_j);
end
if(Node_i ~= Node_j) && (Child.CID(Node_j) ~= Child.CID(Node_i))
k_Node_i_out = k_Node_i_out + A(Node_i, Node_j);
end
end
end
end
11 Commenti
Jan
il 8 Giu 2022
Please porivde some input data. What ist Child.CID ?
Mustafa Abbas
il 8 Giu 2022
Modificato: Mustafa Abbas
il 9 Giu 2022
Dyuman Joshi
il 9 Giu 2022
Modificato: Dyuman Joshi
il 10 Giu 2022
(Int(Node_i) > 0)
What is Int()?
Also, if you define
k_Node_i_in = 0;
k_Node_i_out = 0;
inside your for loop, they will be rewritten at every iteration.
Mustafa Abbas
il 9 Giu 2022
Jan
il 9 Giu 2022
The cheapest acceleration is to avoid the repeated addressing in the struct Child. Copy the contents of Child.CID to the variable CID.
I asked you for providing input data, because it is very hard to optimize code without running it. It is ineffieicnt if all readers write some code to create some data. In addition they could implement wrong ideas and their work is wasted.
I still do not understand, what Int is. A function or array?
Again: Please provide some meaningful input data, e.g. created by rand or randi, such that we can run you code.
Mustafa Abbas
il 9 Giu 2022
Dyuman Joshi
il 9 Giu 2022
Please clarify what exactly Int() is.
Dyuman Joshi
il 9 Giu 2022
So, is it a numeric array?
Mustafa Abbas
il 10 Giu 2022
Jan
il 10 Giu 2022
@Dyuman Joshi: Look onto the data and the provided script: "Int" is "NumInteractionProtein" in the MAT file.
Mustafa Abbas
il 10 Giu 2022
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su App Building in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!