Azzera filtri
Azzera filtri

Output of sprintf - string?

3 visualizzazioni (ultimi 30 giorni)
Gennaro Arguzzi
Gennaro Arguzzi il 11 Mag 2017
Modificato: Stephen23 il 16 Gen 2018
Hi everyone,
on Matlab's documentation I read that sprintf is a function which takes as input data and returns a string. If I write:
x=sprintf('%d',2222)
the output has 1x4 dimension, thus is a character array and not a string (i use Matlab 2015). Why?
Thank you.

Risposta accettata

Stephen23
Stephen23 il 11 Mag 2017
Modificato: Stephen23 il 16 Gen 2018
Because MATLAB only introduced the string class in R2016b, but previously any character array with size 1xN was called a "string". So for historic reasons there are many references to "strings" that are actually references to 1xN char arrays.
For example this includes the functions sprintf, cellstr, and iscellstr.
For the function sprintf:
  • Versions R2016a and before: The output is a 1xN char array.
  • Versions R2016b and later: The output class is the same as that of the first input.

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion 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!

Translated by