Use of dialogue boxes: interactively choosing directory and file to read at the beginning, and "save as" at the end, during the execution of script.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have script that works fine, however since it has not to run only on my pc, I would like to have a script that does not have a fixed directory for looking for txt files at the beginning and one for saving at the end. I would like to have the possibility to choose the text file I have to read at the beginning of the script, and decide where and under what name I want to save the output file when I export my final variable into txt file in the end. I would like to do it interactively using simple dialogue box during the execution of the script. Can anyone help with that? Below is my script.
dir_files='C:\Users\IC5\Desktop\Matlab task';
dir_save='C:\Users\IC5\Desktop\Matlab task\save';
lista=dir(fullfile(dir_files, '*.txt'));
nuova_variabile=[];
nuova_variabile2=[];
for i=1:length(lista)
filename=lista(i).name;
fid=fopen(fullfile(dir_files,filename));
dati=textscan(fid, '%s');
data=dati{1,1};
for j=1:length(data);
if strncmp('$SDDBT',data(j,1), 6)==1;
nuova_variabile=[nuova_variabile; (data(j,1))];
elseif strncmp('$GPGLL',data(j,1), 6)==1;
nuova_variabile=[nuova_variabile; (data(j,1))];
end
end
end
b=char(nuova_variabile);
c=cellstr(b(:,1:6));
idx=strcmp(c,'$SDDBT')';
ii=[1 diff(idx)];
out=nuova_variabile(find(ii~=0));
% then add
ne=ceil(numel(out)/2);
out=cellfun(@(x,y) [x ' ' y],out(1:2:end), out(2:2:end),'un',0);
expression = ' ';
replace = ',';
out2= regexprep(out,expression,replace);
path_file=fullfile('C:\Users\IC5\Desktop\Matlab task\save','output2.txt');
fid=fopen(path_file,'wt');
x=out2;
[rows,cols]=size(x);
for i=1:rows
fprintf(fid,'%s,',x{i,:})
fprintf(fid,'%s\n',x{i,end})
end
fclose(fid);
Thanks in advance
Manuela
0 comentarios
Respuesta aceptada
Tom
el 24 de Jun. de 2013
see the UIGETFILE and UIPUTFILE functions.
doc uigetfile
doc uiputfile
0 comentarios
Más respuestas (2)
Ver también
Categorías
Más información sobre Environment and Settings 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!