Display the content of the cell array

15 visualizaciones (últimos 30 días)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan el 18 de Ag. de 2016
Comentada: Gopalakrishnan venkatesan el 18 de Ag. de 2016
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

Respuesta aceptada

Stephen23
Stephen23 el 18 de Ag. de 2016
Editada: Stephen23 el 18 de Ag. de 2016
>> 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

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by