Vectorizing matrix fitting to a curve
2 views (last 30 days)
Show older comments
Hello,
I have three volume matrices A, B, C of 128x128x128 each.
A represents the data at t1 B represents the data at t2 C represents the data at t3
Now, I need to fit each corresponding voxel to a curve, so I'm using the fit function available in matlab
coefficients=fit(xdata,ydata,myfunction,options);
where
xdata=[t1,t2,t3]
and
ydata=[A(i,j,k),B(i,j,k),C(i,j,k)];
So the way I'm doing this right now is I have to loop through the 128x128x128 voxels of my matrices in order to obtain the fitting coefficients of the curve for each corresponding voxel at the different times and storing them in a cell:
for i=1:128
for j=1:128
for k=1:128
coefficients{i*j*k}=fit([t1,t2,t3],[A(i,j,k),B(i,j,k),C(i,j,k)],myfunction,options);
end
end
end
This is of course taking a very long time.
Is there a way of vectorizing this or at least making it more computational efficient?
I appreciate any help.
Thank you
0 Comments
Answers (2)
HG
on 8 May 2019
Hi, I have an almost identical problem to the one described above. Did you find a solution to your problem?
0 Comments
Dylan Marques
on 5 Jul 2019
Hi,
I am not aware of an easy solution for your question. A possible way of making it faster is to use parfor (https://uk.mathworks.com/help/parallel-computing/parfor.html) so that the for runs in multiple cores.
The faster solution is to make a vectorized version of fit. However this can be complicated to do and time consuming (your time, not the computer time). Which function are you trying to fit to your data?
Many thanks
0 Comments
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox 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!