writing values from cell array to txt file
Mostrar comentarios más antiguos
Hello,
I have a cell array let say of items containing 5 separate lists of items (so, my cell array size is 5x5, each cell containing 5 items). I want to write each list (cell) into a separate txt file.
After browsing over the forum, I came up with this code but it complains about using fprintf with cell input, giving this error: ??? Error using ==> fprintf Function is not defined for 'cell' inputs.
My code is:
for k=1:5
textFilename = ['file' num2str(k) '.txt'];
fid = fopen(textFilename, 'w');
if fid == -1
error('Cannot open file: %s', textFilename);
end
fprintf(fid,'%s',dummy_list(:,k));
end
Can someone please tell me how to accomplish this? I know the hard way is to have another for loop that goes over all the rows for each cell.
Thank you in advance.
8 comentarios
Oleg Komarov
el 9 de Ag. de 2012
Is each cell a cell array or a char aray? In other words, dummy_list{1} is a cell array of 5 strings?
S
el 9 de Ag. de 2012
Yash
el 9 de Ag. de 2012
can you convert the cell array?
S
el 9 de Ag. de 2012
Feng
el 9 de Ag. de 2012
try to use {}, rather than () to access the content of teh cell, like dummy_list{:,k}
S
el 9 de Ag. de 2012
Honglei Chen
el 9 de Ag. de 2012
Can you give an example of your dummy_list, is it something like this?
c = {{'hello' 'yes'} {'no', 'goodbye'}}
and you want to print each entry separately like
hello
yes
S
el 9 de Ag. de 2012
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!