MATLAB Answers

How to print the string value using fprintf

조회 수: 18(최근 30일)
Ganesh Kini
Ganesh Kini 22 Apr 2020
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)
[1,1] = aa
I just want the 'aa' as the output using fprintf only
How do i do that? Kindly help.

  댓글 수: 0

Sign in to comment.

채택된 답변

Rik 22 Apr 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

표시 이전 댓글 수: 5
Rik 22 Apr 2020
For the p{1} part you don't have a choice. The only possibility is to use the curly braces sooner:
p = a{ion};
Ganesh Kini
Ganesh Kini 22 Apr 2020
Okay, Thanks! :)
Stephen Cobeldick
Stephen Cobeldick 23 Apr 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:

Sign in to comment.

추가 답변(0개)

Translated by