Filter löschen
Filter löschen

fprintf matrix question. Need help.

1 Ansicht (letzte 30 Tage)
Berke Gogce
Berke Gogce am 29 Sep. 2019
Bearbeitet: Stephen23 am 11 Okt. 2019
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.

Akzeptierte Antwort

Stephen23
Stephen23 am 11 Okt. 2019
Bearbeitet: Stephen23 am 11 Okt. 2019
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

Weitere Antworten (1)

Deepak Kumar
Deepak Kumar am 11 Okt. 2019
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

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by