How can I convert matlab code to C?

1 次查看(过去 30 天)
Yousef
Yousef 2014-12-10
回答: pramod D Y 2020-5-16
I want to convert my matlab code to c. In the video posted online regarding this, says I should type coder in the command window to build a 'prj' file first. But when I type it I get this error: Undefined function or variable 'coder'. By the way, I already checked to see whether there is supported compiler or not by typing 'mex -setup' in the command window. I would appreciate if anybody could help me out?

回答(2 个)

Orion
Orion 2014-12-10
You need the toolbox Matlab Coder.
in Matlab, type
ver
if Matlab coder is not part of the result, then you can't generate C code from M code.
You're gonna need to buy this toolbox if you want to use coder.
  3 个评论
Adam
Adam 2014-12-10
I don't know what kind of license you have, but yes it is quite expensive since it creates fast C code out of usually slower Matlab code, including support for many builtin Matlab functions.
We have been considering adding it to our Matlab licenses, but the cost means it needs to be very carefully evaluated as to its usefulness.
Sean de Wolski
Sean de Wolski 2014-12-10
Though how expensive is it to rewrite MATLAB Code in C by hand!?

请先登录,再进行评论。


pramod D Y
pramod D Y 2020-5-16
%%
% P = Load vector starting from the right most member
% A = Area vector starting from the right most member
% E = Modulus of Elasticity vector starting from the right most member
% L = Length vector starting from the right most member
%% EXAMPLE:
P=[ 0 -60 0 -40]*1000;
A=(pi/4)[40.^2 40.^2 30.^2 30.^2](10^(-6));
L=[180 120 100 100]./1000;
E=[ 200 200 105 105 ]*10^9;
%% Compute the total force for the ith member
I=length(L); % Numebr of elements
Fi=0;
for i=1:I
Fi=Fi+P(i);
Pf(i)=Fi; % Pf=Computing the total force in each element
end
%% Compute the stress in each element
Sf=Pf./A; % Sf=Computing the stress in each element
%% Compute the deformation in each element
Df=Sf.*L./E; % Df=Computing the deformation in each element
%% Compute the total deformation
DT=sum(Df); % DT = computing the total deformation
%% Compute the deformation due to unit load
UD=L./(A.*E);
%% Compute the total deformation due to unit load
UDT=sum(UD);
%% Reaction at B
RA=-DT./(UDT);
%% Reaction at A
RB=sum(P)+RA;
%% Final stress in each element
Sigma=Sf+RA./A;
%% Final deformation in each element
Delta=Df+RA.*UD;
%% Final Results
II=1:I;
%% Display values
disp(['Reaction at A : ' num2str(RA./1000) ' kN'])
disp(['Reaction at B : ' num2str(RB./1000) ' kN'])
ALL=[II' (1/1000000)*Sigma' 1000.*Delta'];
disp([' Element Stress (MPa) Deformation (mm)' ])
disp(['----------------------------------------------------------' ])
disp(ALL)
disp(['----------------------------------------------------------' ])

类别

Help CenterFile Exchange 中查找有关 Execution Speed 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by