필터 지우기
필터 지우기

How can I convert matlab code to C?

조회 수: 2 (최근 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에서 Stress and Strain에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by