How to use fprintf function?
이전 댓글 표시
I have to print the values of f(x) = sin(x^3) at the points x = 5.201, −8323.6, 0.0003 in floating point (f format) with 8 digits after the decimal and in scientific notation (e format) with 10 digits after the decimal.
Any help at all would be appreciated. I have no clue how to do this.
채택된 답변
추가 답변 (2개)
This should get you started:
>> x = [5.201,-8323.6,0.0003];
>> sprintf(' %.8f',x)
ans = 5.20100000 -8323.60000000 0.00030000
>> sprintf(' %.10e',x)
ans = 5.2010000000e+000 -8.3236000000e+003 3.0000000000e-004
MATLAB has very readable and accessible documentation complete with working examples for you to try out. This is the best place to find out how to do things and how to use functions. You were told what function to use, the next step is to read its documentation and try some of its examples. Then you can see how these can be adapted to your needs, try some small changes... keep on going until you have figured out the problem. Note you should not try to solve any code problem by sitting down writing code! The most important steps are to first understand the problem and then to understand what tools you have to help you, only then comes writing some code...
Here is the fprintf documentation:
I would also highly recommend that you do these tutorials, which are an excellent introduction to MATLAB:
댓글 수: 4
Kaylene Widdoes
2015년 9월 10일
Steven Lord
2015년 9월 10일
Don't copy and paste the lines that start with "ans =". Those are the output from the commands on the previous lines (the lines that start with ">>".)
Kaylene Widdoes
2015년 9월 10일
Kaylene Widdoes
2015년 9월 10일
X=(5-19/7+2.5^3)^2
댓글 수: 1
Walter Roberson
2024년 7월 30일
I do not understand how this answer helps people use fprintf() ?
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
