Borrar filtros
Borrar filtros

How can I convert matlab code to C?

2 visualizaciones (últimos 30 días)
Yousef
Yousef el 10 de Dic. de 2014
Respondida: pramod D Y el 16 de Mayo de 2020
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?

Respuestas (2)

Orion
Orion el 10 de Dic. de 2014
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 comentarios
Adam
Adam el 10 de Dic. de 2014
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 el 10 de Dic. de 2014
Though how expensive is it to rewrite MATLAB Code in C by hand!?

Iniciar sesión para comentar.


pramod D Y
pramod D Y el 16 de Mayo de 2020
%%
% 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(['----------------------------------------------------------' ])

Categorías

Más información sobre Stress and Strain en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by