Cant execute my nested sub-functions

6 visualizzazioni (ultimi 30 giorni)
This is the question i'm stuck on:
In Problem 6.10 you were asked to create and use three different temperature- conversion functions, based on the following conversion equations: (Done in my code below) Recreate Problem 6.10 using nested subfunctions. The primary function should be called temperature_conversions and should include the subfunctions F_to_K C_to_R C_to_F Within the primary function use the subfunctions to:
(a) Generate a conversion table for values from 0°F to 200°F. Include a col- umn for temperature in Fahrenheit and Kelvin.
(b) Generate a conversion table from 0°C to 100°C. Print 25 lines in the table. (Use the linspace function to create your input vector.) Your table should include a column for temperature in Celsius and Rankine.
(c) Generate a conversion table from 0°C to 100°C. Choose an appropriate spacing. Include a column for temperature in Celsius and Fahrenheit. Recall that you will need to call your primary function from the command window or from a script M-file.
code so far is this..
function []=temperature_conversions()
function R=C_to_F(C)
%this function will convert celcius to fahrenheit
disp('C_to_F')
R=(C.*9/5)+32;
end
function R=C_to_R(C)
%this function will convert celcius to rankine
disp('C_to_R')
R=(C.*9/5)+491.67;
end
function K=F_to_K(F)
%this function will convert fahrenheit to kelvin
disp('F_to_K')
F=linspace(0,200,20);
K=(F+459.67).*5/9;
end
end
I want to try to execute this code some individually each piece works but i guess i need multiple inputs/outputs or something??

Risposta accettata

James Tursa
James Tursa il 17 Apr 2018

You need to put code in your primary function to call the subfunctions to create the tables. E.g.,

function []=temperature_conversions()
%
% You write a bunch of code here to create the tables by calling the subfunctions
%
function R=C_to_F(C)

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by