RovingCalypso Posted December 15, 2007 Report Share Posted December 15, 2007 Hello there, Sorry for the odd first post but am really desperate here. Can anybody please convert the following matlab code to labview? It will be a big help. clear; colordef white;p=input('How many poles '); % No. of polestheta=linspace(0,2*pi,50); n=length(theta);ro=6; rs=5; rr=4; % Outside, bore, & rotor radiirgr=4.5; % Air gap center grid radiusRo=ro*ones(1,n);Rs=rs*ones(1,n);Rgr=rgr*ones(1,n);Rr=rr*ones(1,n);F=zeros(1,n); F1=F; F2=F; phi=pi/4;for i=1:37; pause(0.001); polar(theta,Ro,'-.'); hold on; polar(theta,Rs,'-.'); polar(theta,Rgr,'m'); polar(theta,Rr,'g-.');for j=1:n; F1(j)=Rr(j)+0.5+0.225*cos(p/2*theta(j)-phi);F2(j)=Rr(j)+0.5+0.225*cos(p/2*theta(j)+phi);F(j)=F1(j)+F2(j)-Rr(j)-0.5; endpolar(theta,F,'r'); polar(theta,F1,'y:'); polar(theta,F2,'c-.');text(0.9,rs+0.25,'Stator');text(-1.5,rr-0.75,'Rotor');text(5.5,5,'.. Forward');text(5.5,4,'-. Backward');text(5.5,6,'- Resultant');name=['Air gap mmf waves of single-phase induction motor'; ' '; ' ']; title(name);phi=phi+pi/18; hold off;end Any help will be appreciated Thanks alot Quote Link to comment
Tomi Maila Posted December 15, 2007 Report Share Posted December 15, 2007 There are a few alternatives to call Matlab code directly from LabVIEW. First in the latest LabVIEW version 8.5 there is a new structure called MathScript node. This structure can execute Matlab scripts directly within LabVIEW. However not all Matlab functionality, especially toolkits are available. Then there is an older structure called MATLAB Script node that uses ActiveX under Windows to communicate with Matlab installed on your computer. Third option is to call Matlab directly via the ActiveX interface. Refer to Matlab documentation to find out how the ActiveX interface can be used to call Matlab from external programs. Quote Link to comment
Eugen Graf Posted December 15, 2007 Report Share Posted December 15, 2007 QUOTE(Tomi Maila @ Dec 14 2007, 02:09 PM) There are a few alternatives to call Matlab code directly from LabVIEW. First in the latest LabVIEW version 8.5 there is a new structure called MathScript node. This structure can execute Matlab scripts directly within LabVIEW. However not all Matlab functionality, especially toolkits are available. Then there is an older structure called MATLAB Script node that uses ActiveX under Windows to communicate with Matlab installed on your computer. Third option is to call Matlab directly via the ActiveX interface. Refer to Matlab documentation to find out how the ActiveX interface can be used to call Matlab from external programs. QUOTE The LabVIEW MathScript syntax is similar to the MATLAB® language syntax. Similar != the same Quote Link to comment
LAVA 1.0 Content Posted December 15, 2007 Report Share Posted December 15, 2007 QUOTE(RovingCalypso @ Dec 14 2007, 03:28 AM) Can anybody please convert the following matlab code to labview? It will be a big help. I think you'll need to separate the UI functions from the calculations before you can implement this in LabVIEW. MathScript can be used to perform some of the calculations, but the I/O functions like "input" "polar" "text" etc... are not really applicable. The functions used are basic enough that you shouldn't need to use a MathScript node at all. Break the Matlab script into logical parts. such as "get number of poles", "create a 50 element array of angle,length pairs", "for each element in the array, calculate angle,length using a constant value, a 'cos' function and the 'number of poles'", "plot data". Don't try to update a polar chart graph on the fly in LabVIEW.Think this way, "Gather inputs", "Calculate points" and finally "Present output". The updating of the polar plot during the calculations was probably done in the Matlab script because it's convenient. It can be done in LabVIEW but will complicate your code. If you're not familiar Matlab OR LabVIEW, I suspect this is going to take you a long time... Quote Link to comment
Anders Björk Posted December 15, 2007 Report Share Posted December 15, 2007 QUOTE(RovingCalypso @ Dec 14 2007, 09:28 AM) Hello there,Sorry for the odd first post but am really desperate here. Can anybody please convert the following matlab code to labview? It will be a big help.clear; colordef white;<BR>p=input('How many poles '); % No. of poles<BR>theta=linspace(0,2*pi,50); n=length(theta);<BR>ro=6; rs=5; rr=4; % Outside, bore, & rotor radii<BR>rgr=4.5; % Air gap center grid radius<BR>Ro=ro*ones(1,n);Rs=rs*ones(1,n);Rgr=rgr*ones(1,n);Rr=rr*ones(1,n);<BR>F=zeros(1,n); F1=F; F2=F; phi=pi/4;<BR>for i=1:37; pause(0.001);<BR> polar(theta,Ro,'-.'); hold on; polar(theta,Rs,'-.');<BR> polar(theta,Rgr,'m'); polar(theta,Rr,'g-.');<BR>for j=1:n; <BR>F1(j)=Rr(j)+0.5+0.225*cos(p/2*theta(j)-phi);<BR>F2(j)=Rr(j)+0.5+0.225*cos(p/2*theta(j)+phi);<BR>F(j)=F1(j)+F2(j)-Rr(j)-0.5; end<BR>polar(theta,F,'r'); polar(theta,F1,'y:'); polar(theta,F2,'c-.');<BR>text(0.9,rs+0.25,'Stator');text(-1.5,rr-0.75,'Rotor');<BR>text(5.5,5,'.. Forward');text(5.5,4,'-. Backward');<BR>text(5.5,6,'- Resultant');<BR>name=['Air gap mmf waves of single-phase induction motor';<BR> ' ';<BR> ' ']; title(name);<BR>phi=phi+pi/18; hold off;<BR>end Any help will be appreciatedThanks alot Here you have some hint for the calculation parts.http://lavag.org/old_files/monthly_12_2007/post-5713-1197653502.png' target="_blank"> BRAnders Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.