Display a cell in an fprintf?

I'm using an array from an Excel spreadsheet, and am trying to display a 1x1 cell output. However, fprintf doesn't support cell array arguments. When I use it, I get the message,
"Error using fprintf
Function is not defined for 'cell' inputs."
Is there another function I could use to display the cell? Or would I need to convert it to another form before I can use it?

Respuestas (1)

Walter Roberson
Walter Roberson el 26 de Nov. de 2022
You can use celldisp to display a cell, but the result is somewhat verbose, not a nice format.
What you would normally do with a cell and fprintf() is dereference the cell into its contents. Watch out that if you have fewer % format items than entries in the matrix that the format will be repeated as many times as required to output all of the items.
C = {[1], [2 3]}
C = 1×2 cell array
{[1]} {[2 3]}
fprintf('%d,', C{1}); fprintf('\n')
1,
fprintf('%d,', C{2}); fprintf('\n')
2,3,

Categorías

Más información sobre Data Types en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Nov. de 2022

Respondida:

el 26 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by