How to print the string value using fprintf

32 vues (au cours des 30 derniers jours)
Ganesh Kini
Ganesh Kini le 22 Avr 2020
Modifié(e) : Stephen23 le 23 Avr 2020
Hi,
a = (aa bb cc dd)
for ion = 1: 1: length (a)
and some lines of code
then later i have some functionality
---------------
p = a (ion);
Results if i use
fprintf ( "% 10s" , p);
error: fprintf: wrong type argument 'cell'
suppose if i use
disp (p)
output
{
[1,1] = aa
}
I just want the 'aa' as the output using fprintf only
How do i do that? Kindly help.

Réponse acceptée

Rik
Rik le 22 Avr 2020
The error message explains what is going on: you are trying to use a cell as input to fprintf. fprintf will not 'unpack' that for you, so you'll have to do it on your own:
fprintf ( "% 10s" , p{1});
  8 commentaires
Ganesh Kini
Ganesh Kini le 22 Avr 2020
Okay, Thanks! :)
Stephen23
Stephen23 le 23 Avr 2020
Modifié(e) : Stephen23 le 23 Avr 2020
"...i wanted to know if there are other ways of representing it."
There is no "representing" occuring, it is simply the MATLAB syntax for accessing the contents of a cell array:

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by