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 (최근 30일)
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!