Creating a table of two indexes
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to make a temperature conversion table but when I print at the end, all my values are jumbled. How can I seperate the calculations and label the results for each?
bF = input('Input the beginning temperature in Fahrenheit');
eF = input('Input the endung temperature in Fahrenheit');
disp('Temperature in Fahrenheit & Celcuis')
F = [bF:10:eF];
for k = 1
C = (F-32)*(5/9);
end
fprintf('%8.1f\t%8.1f\n',F.',C.')
댓글 수: 0
채택된 답변
Benjamin Kraus
2020년 12월 3일
You need to merge F and C into a single matrix and transpose that matrix:
fprintf('%8.1f\t%8.1f\n',[F' C']')
댓글 수: 4
Benjamin Kraus
2020년 12월 3일
As your code demonstrates, it is not necessary to use a for loop to perform the same computation on every element of a vector in MATLAB. You can do that in one line of code without a loop.
The requirement to use a loop looks like a homework requirement. You can do this using a for loop, but it isn't necessary, and your current code is not using the for loop correctly.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!