Display the content of the cell array
조회 수: 15 (최근 30일)
이전 댓글 표시
Gopalakrishnan venkatesan
2016년 8월 18일
댓글: Gopalakrishnan venkatesan
2016년 8월 18일
I have a cell array a = {'Ford' , 'AUDI'}
I want to display content in the cell array
i tried using a = sprintf('The selected cars are: %s', a{:})
disp(a)
i am getting the output as ''The selected cars are: FordThe selected cars are: AUDI''
But i should get the output as ''The selected cars are: Ford, AUDI
Where did i went wrong?
Thank you
댓글 수: 0
채택된 답변
Stephen23
2016년 8월 18일
편집: Stephen23
2016년 8월 18일
>> sprintf('The selected cars are:%s',sprintf(' %s,',a{:}))
ans = The selected cars are: Ford, AUDI,
Or if you do not want the trailing comma, then in two steps:
>> tmp = sprintf(' %s,',a{:});
>> sprintf('The selected cars are:%s',tmp(1:end-1))
ans = The selected cars are: Ford, AUDI
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!