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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by