Open multiple file as string
Mostrar comentarios más antiguos
Hi guys,
I have a question.
I have different file like string, and I want to open it togheter, without write the name
I tryd this code, but in this way I have to write the name of single file.
Have you advice about it?
directory='D:\Documents\numeric\pip\';
fittingresultspath = 'D:\Documents\numeric\fitting_results\pip\';
fid = -1; msg = ''; while fid < 0
disp(msg); filename = input('input: ','s'); fid=1;
end
Thank you so much
8 comentarios
Geoff Hayes
el 10 de Abr. de 2020
FC - do you want to keep prompting the user for a file (to read) until the file can be opened?
msg = '';
while fid < 0
disp(msg);
filename = input('input: ','s');
fid=fopen(filename, 'r');
end
% do something with the file
% close the file
fclose(fid);
Fredic
el 11 de Abr. de 2020
Geoff Hayes
el 11 de Abr. de 2020
FC - you'll need to open the files one by one possibly with a loop. I don't understand why you'd want to open them all at once. Also, what do you mean by series of files like string?
Fredic
el 11 de Abr. de 2020
Geoff Hayes
el 11 de Abr. de 2020
I'm not really sure what you mean by for a series of files "s" string. What happens when you try something like
while true
filename = input('please input a file name: ','s');
fid=fopen(filename, 'r');
if fid > 0
% do something with file
% close file
fclose(fid);
else
fprintf('Could not open file %s\n', filename);
end
response = input('Are you finished (Y/N): ','s');
if strcmpi(response,'Y')
break;
end
end
Fredic
el 11 de Abr. de 2020
Geoff Hayes
el 11 de Abr. de 2020
Fredic
el 12 de Abr. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Debugging and Analysis 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!