Clear Filters
Clear Filters

How to avoid for-loop in the following code

2 views (last 30 days)
Silke
Silke on 25 Feb 2013
Hi,
I have two data sets data_1 and data_2 of size 256x256xn. One coordinate-vector thr size 1xn and one data set data_mean of size 1xn.
What I want to do is the following:
for r=1:256
for c=1:256
thr_1=interp1(data_1(r,c,:),thr,data_mean);
thr_2=interp1(data_2(r,c,:),thr,data_mean);
tb(r,c,:) = (thr-th_1)./(thr_2-thr_1);
end
end
Unfortunately I have no idea how to avoid the for-loops as the interpolation does not interpolate the data but somehow the grid.
Are there any hints how to speed this code up?
Thanks
  1 Comment
ChristianW
ChristianW on 25 Feb 2013
Is that loop working? interp1 syntax has as first input the coordinate vector. Is thr or data_1 your coordinate vector? Can your interp1 deal with unsqueezed inputs (dim 1x1xn)? The var th_1 is unassigned, most likely a typing error. This suggests your loop never worked.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!