You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how to use external function in app designer?
18 views (last 30 days)
Show older comments
i have created a matlab fuction which will print multiple output how to use it in app designer.i called that fuction but i got an error that multiple outputs to print.what to do now?
Answers (1)
Cris LaPierre
on 22 Jun 2022
9 Comments
GOURANG UPADHYAY
on 22 Jun 2022
Edited: GOURANG UPADHYAY
on 22 Jun 2022
this will not work for me.i have already seen it.
GOURANG UPADHYAY
on 22 Jun 2022
function faultfrequency(N1,Ra)
T1=31;T2=106;T3=56;T4=108;%Number of teeth on each gear
N2=T1*N1/T2;N3=N2*T3/T4;%RPM calculation
%%Bearing Fault Frequency calculation
%1.Spherical Roller Bearing SKF 22316 B1
%D1 Shoulder/recess diameter of outer ring
%d2 Shoulder diameter of inner ring
%BD Rolling Element dia
%Pd Pitch dia
%Nd NUmber of Rolling Elemrnt
D1=143;d2=98.3;ca=12.95;Nb=15;Pd=(D1+d2)/2;Bd=12.15*2;N=N1;
BPFO1=(N*Nb/120)*(1-((Bd/Pd)*cosd(ca)));%Ball Pass Frequency Outer
BPFI1=(N*Nb/120)*(1+((Bd/Pd)*cosd(ca)));%Ball Pass Frequency Inner
BSF1=(Pd*N/(Bd*60))*(1-((Bd/Pd)*cosd(ca))^2);%Ball Spin Frequency
FTF1=(N/120)*(1-((Bd/Pd)*cosd(ca)));%Fundamental Train Frequency
%Cylindrical Roller Bearing SKF NJ 2212 ECJ B2
F=72;Bd=14;ca=0;Nb=16;D=F+(2*Bd);Pd=(D+F)/2;N=N1;
BPFO2=(N*Nb/120)*(1-((Bd/Pd)*cosd(ca)));
BPFI2=(N*Nb/120)*(1+((Bd/Pd)*cosd(ca)));
BSF2=(Pd*N/(Bd*60))*(1-((Bd/Pd)*cosd(ca))^2);
FTF2=(N/120)*(1-((Bd/Pd)*cosd(ca)));
%Spherical Roller Bearing SKF 22316 E B3
D1=143;d2=98.3;ca=12.95;Nb=15;Pd=(D1+d2)/2;Bd=12.15*2;N=N2;
BPFO3=(N*Nb/120)*(1-((Bd/Pd)*cosd(ca)));
BPFI3=(N*Nb/120)*(1+((Bd/Pd)*cosd(ca)));
BSF3=(Pd*N/(Bd*60))*(1-((Bd/Pd)*cosd(ca))^2);
FTF3=(N/120)*(1-((Bd/Pd)*cosd(ca)));
%Cylindrical Roller Bearing SKF NJ 2310 ECP B4
F=65;Bd=16;ca=0;Nb=23;D=F+(2*Bd);Pd=(D+F)/2;N=N2;
BPFO4=(N*Nb/120)*(1-((Bd/Pd)*cosd(ca)));
BPFI4=(N*Nb/120)*(1+((Bd/Pd)*cosd(ca)));
BSF4=(Pd*N/(Bd*60))*(1-((Bd/Pd)*cosd(ca))^2);
FTF4=(N/120)*(1-((Bd/Pd)*cosd(ca)));
%Cylindrical Roller Bearing SKF NJ 218 ECP B5
F=107;Bd=19;ca=0;Nb=17;D=F+(2*Bd);Pd=(F+D)/2;N=N3;
BPFO5=(N*Nb/120)*(1-((Bd/Pd)*cosd(ca)));
BPFI5=(N*Nb/120)*(1+((Bd/Pd)*cosd(ca)));
BSF5=(Pd*N/(Bd*60))*(1-((Bd/Pd)*cosd(ca))^2);
FTF5=(N/120)*(1-((Bd/Pd)*cosd(ca)));
%Spherical Roller Thrust Bearing SKF 29436E B6
Bd=16.61;ca=44.01;Nb=15;Pd=171.5;N=N3;
BPFO6=(N*Nb/120)*(1-((Bd/Pd)*cosd(ca)));
BPFI6=(N*Nb/120)*(1+((Bd/Pd)*cosd(ca)));
BSF6=(Pd*N/(Bd*60))*(1-((Bd/Pd)*cosd(ca))^2);
FTF6=(N/120)*(1-((Bd/Pd)*cosd(ca)));
%Cylindrical Roller Bearing SKF NJ 217 ECP
F=100.5;Bd=18;ca=0;Nb=17;D=F+(2*Bd);Pd=(D+F)/2;N=N3;
BPFO7=(N*Nb/120)*(1-((Bd/Pd)*cosd(ca)));
BPFI7=(N*Nb/120)*(1+((Bd/Pd)*cosd(ca)));
BSF7=(Pd*N/(Bd*60))*(1-((Bd/Pd)*cosd(ca))^2);
FTF7=(N/120)*(1-((Bd/Pd)*cosd(ca)));
%Harmonics
ff=zeros(28,5);
no=[1,5,9,13,17,21,25];
for i=no
for j=1:5
switch i
case 1
ff(i,j)=BPFO1*j;
ff(i+1,j)=BPFI1*j;
ff(i+2,j)=BSF1*j;
ff(i+3,j)=FTF1*j;
case 5
ff(i,j)=BPFO2*j;
ff(i+1,j)=BPFI2*j;
ff(i+2,j)=BSF2*j;
ff(i+3,j)=FTF2*j;
case 9
ff(i,j)=BPFO3*j;
ff(i+1,j)=BPFI3*j;
ff(i+2,j)=BSF3*j;
ff(i+3,j)=FTF3*j;
case 13
ff(i,j)=BPFO4*j;
ff(i+1,j)=BPFI4*j;
ff(i+2,j)=BSF4*j;
ff(i+3,j)=FTF4*j;
case 17
ff(i,j)=BPFO5*j;
ff(i+1,j)=BPFI5*j;
ff(i+2,j)=BSF5*j;
ff(i+3,j)=FTF5*j;
case 21
ff(i,j)=BPFO6*j;
ff(i+1,j)=BPFI6*j;
ff(i+2,j)=BSF6*j;
ff(i+3,j)=FTF6*j;
case 25
ff(i,j)=BPFO7*j;
ff(i+1,j)=BPFI7*j;
ff(i+2,j)=BSF7*j;
ff(i+3,j)=FTF7*j;
end
end
end
for a=1:28
for b=1:5
ul=ff(a,b)*2^(1/6);
ll=ff(a,b)*2^(-1/6);
if a<=4
x=1;
elseif a>4 && a<=8
x=2;
elseif a>8 && a<=12
x=3;
elseif a>12 && a<=16
x=4;
elseif a>16 && a<=20
x=5;
elseif a>20 && a<=24
x=6;
elseif a>24 && a<=28
x=7;
end
b1=1:4:28;
b2=2:4:28;
b3=3:4:28;
b4=4:4:28;
if ll<=Ra && ul>=Ra
if ismember(a,b1)==1
fprintf("defect is in outer race of bearing %d and corresponding harmonics is %d and value is %d:\n ",x,b,ff(a,b))
elseif ismember(a,b2)==1
fprintf("defect is in outer race of bearing %d and corresponding harmonics is %d and value is %d:\n ",x,b,ff(a,b))
elseif ismember(a,b3)==1
fprintf("defect is in outer race of bearing %d and corresponding harmonics is %d and value is %d:\n ",x,b,ff(a,b))
elseif ismember(a,b4)==1
fprintf("defect is in outer race of bearing %d and corresponding harmonics is %d and value is %d:\n ",x,b,ff(a,b))
else
fprintf("No bearing defect:\n")
end
end
end
end
%% Gear fault frequencies
%input satge
GMF1=T1*N1/60;%Gear Meash Frequency
NA1=gcd(T1,T2);%Number of Assembly Phases
HTF1=(GMF1*NA1)/(T1*T2);%Hunting Tooth Frequency
APF1=GMF1/NA1;%Assembly Phase Frequency
%input satge
GMF2=T3*N2/60;%Gear Meash Frequency
NA2=gcd(T3,T4);%Number of Assembly Phases
HTF2=(GMF2*NA2)/(T3*T4);%Hunting Tooth Frequency
APF2=GMF2/NA2;%Assembly Phase Frequency
fg=zeros(6,5);
nog=[1 4];
for i=nog
for j=1:5
if i==1
fg(i,j)=GMF1*j;
fg(i+1,j)=HTF1*j;
fg(i+2,j)=APF1*j;
elseif i==4
fg(i,j)=GMF2*j;
fg(i+1,j)=HTF2*j;
fg(i+2,j)=APF2*j;
end
end
end
for a=1:6
for b=1:5
ul=fg(a,b)*2^(1/6);
ll=fg(a,b)*2^(-1/6);
if a<=3
x=1;
elseif a>3 && a<=6
x=2;
end
b1=1:3:4;
b2=2:3:6;
b3=3:3:6;
if ll<=Ra && ul>=Ra
if ismember(a,b1)==1
fprintf("defect is in stage %d (check wear and lubrication)and corresponding harmonics of GMF is %d and corresponding frequency is %d\n ",x,b,fg(a,b))
elseif ismember(a,b2)==1
fprintf("defect is in stage %d and corresponding harmonics of HTF is %d and corresponding frequency is %d\n ",x,b,fg(a,b))
elseif ismember(a,b3)==1
fprintf("defect is in stage %d and corresponding harmonics of APF is %d and corresponding frequency is %d\n ",x,b,fg(a,b))
end
end
end
end
This is my function .please help
Cris LaPierre
on 22 Jun 2022
I wouldn't use fprintf. Based on the little I know, I would use a text edit field (see all options here) and set the edit field value equal to the statement you are creating using fprintf.
GOURANG UPADHYAY
on 22 Jun 2022
please suggest how should i convert my function in to app i am stucked un to it .i am new to app designer and not able to understand it at all.
Cris LaPierre
on 22 Jun 2022
Apologies. It was the middle of the night so I was sleeping. It is unclear to me what you are struggling to do now. Perhaps this Answer of custom functions will help:
Other suggestion include going through the app designer tutorial, and finding an example app to learn from.
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)