Convert matlab code to C code using matlab coder

Hi i've been trying to convert some code that reads excel files and manipulate them into C code using Matlab coder. I'm using some matlab functions like xlsread, dir, xlswrite. I've gotten errors like they are not supported and script is not supported. I know it's because the functions are not supported. How do i go about correcting this? My full code is below.
filename = dir('*xlsx');
filename = struct2cell(filename);
Maxsize=size(filename);
format long g;
for x=1:+1:Maxsize(1,2)
for page=1:+1:3
data1=xlsread(char(filename(1,x)),page,'D5:D12');
data2=xlsread(char(filename(1,x)),page,'H5:H12');
data3=xlsread(char(filename(1,x)),page,'L5:L12');
X=xlsread(char(filename(1,x)),page,'C15');
waferleftX=data1(1,1);
waferleftY=data1(2,1);
wafertopX=data2(1,1);
wafertopY=data2(2,1);
wafercenterX=data2(4,1);
wafercenterY=data2(5,1);
waferbotX=data2(7,1);
waferbotY=data2(8,1);
waferrightX=data3(1,1);
waferrightY=data3(2,1);
yoff=(wafertopY+waferbotY)/2;
xoff=(waferleftX+waferrightX)/2;
if (xoff>0)
newwaferleftX=waferleftX-abs(xoff);
newwaferrightX=waferrightX-abs(xoff);
newwafertopX=wafertopX-abs(xoff);
newwaferbotX=waferbotX-abs(xoff);
else
newwaferleftX=waferleftX+abs(xoff);
newwaferrightX=waferrightX+abs(xoff);
newwafertopX=wafertopX+abs(xoff);
newwaferbotX=waferbotX+abs(xoff);
end
if (yoff>0)
newwafertopY=wafertopY-abs(yoff);
newwaferbotY=waferbotY-abs(yoff);
newwaferleftY=waferleftY-abs(yoff);
newwaferrightY=waferrightY-abs(yoff);
else
newwafertopY=wafertopY+abs(yoff);
newwaferbotY=waferbotY+abs(yoff);
newwaferleftY=waferleftY+abs(yoff);
newwaferrightY=waferrightY+abs(yoff);
end
Y=(abs(newwaferleftY)+abs(newwaferrightY)+abs(newwafertopX)+abs(newwaferbotX))/4;
DeltaL=(abs(newwaferleftX)+abs(newwaferrightX)+abs(newwafertopY)+abs(newwaferbotY))/4;
theta=atan(Y/X);
Rotation=theta/0.000001;
Mag=DeltaL/X*1000000;
xlswrite(char(filename(1,x)),xoff,page,'K15');
xlswrite(char(filename(1,x)),yoff,page,'K16');
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2016년 6월 16일

0 개 추천

The supported external functions are a subset of the Standard C library. MATLAB Coder effectively only supports generating code that could be implemented in pure C on a system that had no operating system. Tasks such as xlswrite() are much too complex for direct support.
You will need to use something like coder.ceval() to call a third-party external library that can handle the creation or update of xlsx files.

댓글 수: 2

Thanks for the reply. So what should i do with my code exactly?
See the examples
You will need to tell the code generator the data types of the arguments that your xlswrite function will expect. And you will need to write your own xlswrite C or C++ code or find someone's pre-written library.
If you are specifically targetting MS Windows then you could consider writing the code in terms of ActiveX / DCOM . See http://www.mathworks.com/matlabcentral/fileexchange/10465-xlswrite1
Have you consider the possibility of using csv files instead of xlsx files? csv files are much easier to output.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2016년 6월 16일

댓글:

2016년 6월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by