Clear Filters
Clear Filters

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

19 views (last 30 days)
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 Comments
Rik
Rik on 9 Jun 2023

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.

Sign in to comment.

Answers (0)

Categories

Find more on Create Custom UI Components in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!