How to improve the speed of of this function?
2 views (last 30 days)
Show older comments
Good Morning, I am looking for some advice regarding improving the efficiency of my code. I have a simple loop I am running but it is the first time I am running it on the entirety of my data set and I now realize how slow my loop is. I am wondering if anyone might have some advice for improving the speed.
TRIAL1A_SPACE1 = zeros(size(T1A_raw_TEMP))
[r, c] = size(TRIAL1A_SPACE1)
for e = 1:r
for f = 1:c
if T1A_raw_TEMP(e,f) >= 8 && T1A_raw_HUM(e,f) >= 11
TRIAL1A_SPACE1(e,f) = 1
end
end
end
The [r,c] = [7824,183].
Thank you for any help or advice!
0 Comments
Answers (2)
Ingrid
on 15 Feb 2016
you do not need a loop for this, you can just use
TRIAL1A_SPACE1 = zeros(size(T1A_raw_TEMP));
TRIAL1A_SPACE1(T1A_raw_TEMP >= 8 && T1A_raw_HUM >= 11 ) = 1;
Jos (10584)
on 15 Feb 2016
The command
TRIAL1A_SPACE1 = T1A_raw_TEMP >= 8 & T1A_raw_HUM >= 11
will make create the required (logical) matrix.
2 Comments
Jos (10584)
on 16 Feb 2016
g = 1:s
h = 1:d-1
TRIAL1A_SPACE3(g,h+1) = TRIAL1A_SPACE1(g,h) == 1 & TRIAL1A_SPACE1(g, h+1) == 1
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!