converting a Fahrenheit degree to a Celsius degree, then use this function in a “for” loop to calculate the equivalent Celsius degrees for the Fahrenheit degrees from 0 to 200
조회 수: 8 (최근 30일)
이전 댓글 표시
for loop
댓글 수: 0
채택된 답변
goc3
2016년 10월 15일
You don't need to use a for loop. See the following vectorized solution:
% create an array from 0 to 200 (default increment of one used)
deg_F = 0:200; %temperature in Fahrenheit
% convert Fahrenheit to Celsius
deg_C = (deg_F - 32) / 9 * 5; %temperature in Celsius
댓글 수: 0
추가 답변 (1개)
Image Analyst
2016년 10월 15일
Try this:
% Make an "anonymous function".
f2c = @(f) (f-32)*5/9;
% Convert all f from 0 to 200 into C
for f = 0 : 200
c = f2c(f);
fprintf('%d F = %.1f C\n', f, c);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!