Using user input for a file name, and then reading a .txt file with the same name.

1 vue (au cours des 30 derniers jours)
Ironmaniac
Ironmaniac le 8 Déc 2016
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?

Réponses (1)

Jos (10584)
Jos (10584) le 8 Déc 2016
X = input('Number','s')
filename = [X '.txt'] ;
titlestring ['figure for file ' X] ;
title(titlestring)
You could also take a look at GETFILE

Community Treasure Hunt

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

Start Hunting!

Translated by