Using user input for a file name, and then reading a .txt file with the same name.
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a number of .txt files. My program to reads one file at a time and then generates a plot. And I have to type the name of the file and the title of the plot generated, manually, everytime. The code is,
data1=importdata('1.txt');
phase=data1(:,3);
p=phase*2*pi; %Phase in cycles?
t=data1(:,1);
fd=diff(p);
t1=t;
t1(end,:) = [];
sd=diff(fd);
t2=t1;
t2(end,:) = [];
figure
ax1=subplot(2,1,1);
plot(ax1,t,p)
title( '15 Jul 2012, SV 1')
xlabel('GPS TOW (milliseconds)')
ylabel('Phase at L1 (cycles)')
%subplot(3,1,2)
%plot(t1,fd)
ax2=subplot(2,1,2);
plot(ax2,t2,sd)
xlabel('GPS TOW (milliseconds)')
ylabel('sec diff on Phase at L1 (cycles)')
axis([ax2],[-inf inf -1.5 1.5])
axis([ax1],[-inf inf -inf inf])
And here is a screenshot,
In the left pane, the *.txt files are the input files. For every .txt as input, I need to modify line 1 and line 14 in the code, for every execution
How can I have the code
(i) ask for the file name? To which I type "1", without the .txt extension. Such that it reads and works on the file.
(ii) And generates the figure and names it "XXXX 1" on its own?
댓글 수: 0
답변 (1개)
Jos (10584)
2016년 12월 8일
X = input('Number','s')
filename = [X '.txt'] ;
titlestring ['figure for file ' X] ;
title(titlestring)
You could also take a look at GETFILE
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!