Using Sprintf on matlab
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Matthew Liao
il 29 Gen 2015
Modificato: Star Strider
il 29 Gen 2015
Part b) Display the content of “log10(A)” on the screen using “sprintf” in the following format: “A is [1 10 100 1000]. log10(A) calculated using the natural logarithm function is [0 1 2 3].” In the format above, where the numbers are bold, the values of “A” and “log10(A)” must be used instead of simply typing the numbers. In other words, do not simply type in the entire line above between two quotation marks of “sprint”, but use a format similar to the following: sprint(‘A is [ %? ]. log10(A) calculated using the natural logarithm function is [ %?]’ ,A,?) What you need to find is the format to display “A” and “log10(A)”, e.g. %u, %d, %s etc (the first and second question marks) and the function you defined in part (a) for the third question mark.
0 Commenti
Risposta accettata
Star Strider
il 29 Gen 2015
5 Commenti
Star Strider
il 29 Gen 2015
Modificato: Star Strider
il 29 Gen 2015
I would use ‘%f’ for the natural logarithm function output as well. The ‘%u’ is for base 10 unsigned integers, and will produce strange results.
This works perfectly for me:
A = [1 10 100 1000];
C = log(A);
logarithmic = sprintf('A is [%f %f %f %f], log10(A) calculated using the natural logarithm function is [%f %f %f %f]',A,C)
and produces:
logarithmic =
A is [1.000000 10.000000 100.000000 1000.000000], log10(A) calculated using the natural logarithm function is [0.000000 2.302585 4.605170 6.907755]
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Entering Commands in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!