Borrar filtros
Borrar filtros

problem using fprintf for writing cell data and global data at the same time.

1 visualización (últimos 30 días)
[fileName, filePath] = uiputfile('*.doc', 'Create a <file:'>)
if ~ischar(fileName)
return;
end
fileID = fopen(fullfile(filePath, fileName), 'w');
cellArray=
'p.4004'
'p.4005'
'p.4007'
cellArray 3x1 cell global
matrix=[1 2 3;4 5 6;7 8 9]
%I can write these values separetely into word like this;
fprintf(fileID,'%47f %f \n',matrix')
fprintf(fileID,'%s\n',cellArray{:})
%but I need to write them together into microsoft word like this;
p.4004 1 2 3
p.4005 4 5 6
p.4007 7 8 9

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 3 de Ag. de 2013
cellArray={'p.4004'
'p.4005'
'p.4007'}
matrix=[1 2 3;4 5 6;7 8 9]
v=[cellArray num2cell(matrix)]
fileID = fopen('fic13.txt', 'w');
for k=1:size(v,1)
fprintf(fileID, '%s %d %d %d\n', v{k,:});
end
fclose(fileID)
  13 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 3 de Ag. de 2013
I don't know what is the problem, when I run the same code, I'am getting the correct answer. Maybe you are checking the wrong file?
sermet
sermet el 3 de Ag. de 2013
ok no problem, I'll try it again carefully, thank you so much for sparing your time.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by