can a live editor .mlx file be run as a program in the app designer code?

12 次查看(过去 30 天)
I am trying to run code that was devloped in live editor to run in a app designer graphical interface. I have multiple loops that would be dependent on choices made and I cannot find good exaples of this type of program that was converted to run in the app designer code to know how to do this. All the examples I have found are simple if you choose option 1 a simple code of equation runs, if you choose option 2 a different simple code or equation runs. I have found no exaples of if option one is chosen, the there are other options loops can run with in the first options choices. I have included the live script program that I want to then set up to run in app designer. If anyone can point me to where I can find good information on programming this code to run in the app designer code, with all the dependent loops, that would be greatly appreciated.
F=input('gasoline or Diesel: ','s');
C=input('number of engine cylinders ');
T=input('trailer being towed yes or no: ','s');
TW=input('trailer weight ');
M=input('trip length in miles ');
c=input('cost of fuel per gallon ');
switch F
case 'gasoline'
if C==4
bmpg=24;
switch T
case 'yes'
if TW<=2000
mpg=bmpg-(bmpg*0.2);
elseif TW>2000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=24;
end
elseif C==6
bmpg=18;
switch T
case 'yes'
if TW<=2000
mpg=bmpg-(bmpg*0.1);
elseif TW>2000 && TW<=4000
mpg=bmpg-(bmpg*0.2);
elseif TW>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=18;
end
elseif C==8
bmpg=12;
switch T
case'yes'
if TW<=2000
mpg=bmpg-(bmpg*0.05);
elseif TW>2000 && TW<=4000
mpg=bmpg-(bmpg*0.1);
elseif TW>4000 && TW<=6000
mpg=bmpg-(bmpg*0.2);
elseif TW>6000 && TW<=8000
mpg=bmpg-(bmpg*0.4);
elseif TW>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=12;
end
end
case 'diesel'
if C==4
bmpg=26;
switch T
case'yes'
if TW<=2000
mpg=bmpg-(bmpg*0.05);
elseif TW>2000 && TW<=4000
mpg=bmpg-(bmpg*0.1);
elseif TW>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=26;
end
elseif C==6
bmpg=22;
switch T
case'yes'
if TW<=2000
mpg=bmpg-(bmpg*0.025);
elseif TW>2000 && TW<=4000
mpg=bmpg-(bmpg*0.5);
elseif TW>4000 && TW<=6000
mpg=bmpg-(bmpg*0.1);
elseif TW>6000 && TW<=8000
mpg=bmpg-(bmpg*0.2);
elseif TW>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=22;
end
elseif C==8
bmpg=18;
switch T
case'yes'
if TW<=2000
mpg=bmpg-(bmpg*0.0125);
elseif TW>2000 && TW<=4000
mpg=bmpg-(bmpg*0.05);
elseif TW>4000 && TW<=6000
mpg=bmpg-(bmpg*0.2);
elseif TW>6000 && TW<=8000
mpg=bmpg-(bmpg*0.4);
elseif TW>8000 && TW<10000
mpg=bmpg-(bmpg*0.6);
elseif TW>10000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=18;
end
end
end
  4 个评论
Rik
Rik 2023-6-9

If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). There is a section about functions.

Once you complete that, you should read this thread for general advice and examples for how to create a GUI.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Create Custom UI Components 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by