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

조회 수: 12 (최근 30일)
Jon
Jon 2023년 6월 8일
댓글: Rik 2023년 6월 9일
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