필터 지우기
필터 지우기

Input multiple items and solve a function for those values?

조회 수: 1 (최근 30일)
Emily
Emily 2013년 10월 16일
댓글: Emily 2013년 10월 16일
℉ = 9/5*℃ + 32
For this problem, write a function m-file that does the following:
1. Accepts two inputs, a low temperature and a high temperature both in Celsius.
2. Defines an anonymous function in the function workspace that converts temperatures from Celsius to
Fahrenheit.
3. Uses the anonymous function to convert each input temperature to Fahrenheit.
4. Calculates the difference between the two temperatures in Fahrenheit.
5. Outputs three results: the low temperature in Fahrenheit, the high temperature in Fahrenheit, and the difference between the temperatures in Fahrenheit.
... So I've got it to where I can convert the two temperature inputs in F to C. But I cannot for the life of me figure out how to calculate the difference between the two and then end up with three outputs. I'm new to Matlab so its all pretty confusing right now and I would really love some advice as to how to approach this problem! Thanks
Here is what I have so far:
prompt = 'Convert temperature to Fahrenheit? ';
result = input(prompt);
str = input(prompt,'s');
F = @(C) ((9./5).*C)+32;
F(result);
disp(X)

답변 (1개)

David Sanchez
David Sanchez 2013년 10월 16일
function [F1,F2,Fd] = my_faran(C1,C2)
F = @(C) ((9./5).*C)+32;
F1 = F(C1);
F2 = F(C2);
Fd = F1-F2;
Call the function like this (change the input values as you please):
[F1,F2,Fd] = my_faran(10,30)
  댓글 수: 1
Emily
Emily 2013년 10월 16일
Thank you so much! I was definitely over thinking that whole thing and confusing my self... it all makes sense now!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Electrical Block Libraries에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by