How to print the string value using fprintf

조회 수: 31 (최근 30일)
Ganesh Kini
Ganesh Kini 2020년 4월 22일
편집: Stephen23 2020년 4월 23일
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.

채택된 답변

Rik
Rik 2020년 4월 22일
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
Ganesh Kini
Ganesh Kini 2020년 4월 22일
Okay, Thanks! :)
Stephen23
Stephen23 2020년 4월 23일
편집: Stephen23 2020년 4월 23일
"...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:

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by