I am not sure how to print multiple variables like strings, arrays and matrices all in one line. Can someone help? See below.
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nick Firrantello
am 30 Nov. 2017
Kommentiert: Nick Firrantello
am 30 Nov. 2017
for i=1:Numberofstations
fprintf('Station ')
fprintf(B(i,1))
fprintf(':')
fprintf(B(i,2))
fprintf('Miles')
fprintf('"')
fprintf(GetStationName(B(i)))
fprintf('"')
fprintf('\n')
When I print this, it should look like: Station 35: .8574 miles, "Street ave"
so "station" is a string, "35" is part of a matrix,":" is a character, ".8574 is part of a matrix, "miles," is a string, and "street ave" is from a function call. Is there an easier way to do this?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 30 Nov. 2017
fprintf('Station ')
fprintf('%d', B(i,1))
fprintf(':')
fprintf('%.4f', B(i,2))
fprintf('Miles,')
fprintf('"')
fprintf('%s', GetStationName(B(i, 3)))
fprintf('"')
Or, more simply,
fprintf('Station %d: %.4f Miles, "%s"\n', B(i,1), B(i,2), GetStationName(B(i, 3)) );
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!