필터 지우기
필터 지우기

fprintf matrix question. Need help.

조회 수: 1 (최근 30일)
Berke Gogce
Berke Gogce 2019년 9월 29일
편집: Stephen23 2019년 10월 11일
Using the repeated feature of fprintf() function in MATLAB, your program must display the results in the following format:
The force in link (I)= XXXX.XX N
The force in link (I)= XXXX.XX N The force in link (-)= ------- N
-------------------------------
Where I refers to the link number (1-8) in format %i and XXXX.XX is the corresponding force value in that link in %g format.

채택된 답변

Stephen23
Stephen23 2019년 10월 11일
편집: Stephen23 2019년 10월 11일
No loop is required:
>> x = 1:8;
>> y = exp(x);
>> fprintf('The force in link (%d)= %g N\n',[x;y])
The force in link (1)= 2.71828 N
The force in link (2)= 7.38906 N
The force in link (3)= 20.0855 N
The force in link (4)= 54.5982 N
The force in link (5)= 148.413 N
The force in link (6)= 403.429 N
The force in link (7)= 1096.63 N
The force in link (8)= 2980.96 N
Or using %f format:
>> fprintf('The force in link (%d)= %4.2f N\n',[x;y])
The force in link (1)= 2.72 N
The force in link (2)= 7.39 N
The force in link (3)= 20.09 N
The force in link (4)= 54.60 N
The force in link (5)= 148.41 N
The force in link (6)= 403.43 N
The force in link (7)= 1096.63 N
The force in link (8)= 2980.96 N

추가 답변 (1개)

Deepak Kumar
Deepak Kumar 2019년 10월 11일
Please refer the below documentaion to understand the uses of fprintf function
Also, I have written the below code to print the value of at the values x=1:8 using for loop. You can refer this code and make changes as per your requirements.
clc
clear all
for x=1:8
fprintf('The value in link(%d)=%4.2f N\n \n',x,exp(x))
end

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by