Convert matlab code to C code using matlab coder
11 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Walter Roberson
2016-6-16
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 个评论
Walter Roberson
2016-6-16
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
or if you are targetting a system that will have Java, see https://www.mathworks.com/matlabcentral/fileexchange/38591-xlwrite--generate-xls-x--files-without-excel-on-mac-linux-win
Have you consider the possibility of using csv files instead of xlsx files? csv files are much easier to output.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!