generating a mex file problem with sum command

Hi I am having a problem converting my MATLAB code to a mex file. I belive the error lies with the sum command , within matlab the sum command sums along one dimension and then removes the dimension but during the mex file generation the summation occurs and but the extra dimension is still there. does anyone know how i could rewrite the lines to get them working within the mex file? in particular the following line: BPvol_seg(:,:,:,seg)=sum(BP,4);
Here is the matlab function code:
function BPVOL=SAFT3DTDRECON(fullcscan,dx,dy,sampleRate,f,c,ReconRatio)
%input Recon parameters
x=0:dx:(size(fullcscan,1)-1)*dx;
y=0:dy:(size(fullcscan,2)-1)*dy;
z=0:(c/sampleRate):(size(fullcscan,3)-1)*(c/sampleRate);
dt=1/sampleRate;
dpx=x;
dpy=y;
%solve the 3D recon in depth segments given by the ReconRatio
ReconDepthSegment=(size(fullcscan,3))/ReconRatio;
section=1:ReconDepthSegment:(size(fullcscan,3));
%generate x,y, dp and f matrices to avoid for nested loop
y_mat=repmat(y,size(x,2),1, ReconDepthSegment,size(dpx,2),size(dpy,2));
x_mat=repmat(x',1,size(y,2),ReconDepthSegment,size(dpx,2),size(dpy,2));
dpx_mat=permute(x_mat,[4,2,3,1,5]);
dpy_mat=permute(y_mat,[5,2,3,4,1]);
delpx_mat= (x_mat-dpx_mat).^2;
delpy_mat= (y_mat-dpy_mat).^2;
%clear y_mat x_mat dpx_mat dpy_mat
%preallocate
Td_d=zeros(size(x,2),size(y,2),ReconDepthSegment,size(dpx,2),size(dpy,2));
BP=zeros(size(x,2),size(y,2),ReconDepthSegment,size(dpx,2),size(dpy,2));
BPvol_seg=zeros(size(x,2),size(y,2),ReconDepthSegment,ReconRatio);
for seg=1:ReconRatio
seg
z_seg=z(section(seg):(ReconDepthSegment+section(seg)-1));
z_mat=repmat(z_seg,size(x,2),1,size(y,2),size(dpx,2),size(dpy,2));
z_mat=permute(z_mat,[1,3,2,4,5]);
Td_d= round((f+sqrt((z_mat-f).^2+delpy_mat+delpx_mat)/c)/dt)*dt; %discrete Time delay matrix
for i=1:1:(size(fullcscan,1))
for j=1:1:(size(fullcscan,2))
Ascan=fullcscan(i,j,:);
index=round(Td_d(:,:,:,i,j)/dt+1);
for m=1:1:(size(index,1))
for n=1:1:(size(index,2))
for o=1:1:(size(index,3))
if index(m,n,o)<=length(Ascan)
BP(m,n,o,i,j)=Ascan(index(i,j,o));
else
BP(m,n,o,i,j)=0;
end
end
end
end
end
end
%sum all BP frames to generate Backprojection volume
BP=(sum(BP,5));
BPvol_seg(:,:,:,seg)=sum(BP,4);
end
BPVOL=reshape(BPvol_seg,size(BPvol_seg,1),size(BPvol_seg,2),size(BPvol_seg,3)*size(BPvol_seg,4));

2 Kommentare

How do you generate the mex file?
Zak Ali
Zak Ali am 3 Sep. 2020
Bearbeitet: Zak Ali am 3 Sep. 2020
by following this tutorial:
if you paste the code within the Matlab C++ the error will appear.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB Coder finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2017b

Gefragt:

am 3 Sep. 2020

Bearbeitet:

am 3 Sep. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by