After importing multiple multicolumn txt files using "dlmread" function. Now i have 10 txt files each contains 12 columns, How can i go through all those 10 txt files and plot graphs for all subsequent 2 columns iteratively..
Show older comments
for k = 1:length(theFiles) baseFileName = theFiles(k).name; fullFileName = fullfile(myFolder, baseFileName); fprintf(baseFileName,'%2d\n', k); %fullFileName = dlmread(fullFileName,'',1,0) READ=dlmread(fullFileName,'',1,0) end
Accepted Answer
More Answers (1)
Adam Danz
on 22 Aug 2018
(continuing from comments under the question).
There are some problems to fix in the current code before we move on to the question at hand.
First, you are reading in data from your 10 txt files but you are not saving the data. Instead, you are overwriting the data at each iteration of your for-loop. If (and only if) all of your data have the same number of columns, you can combine the data from all 10 files like this.
allData = [];
for k = 1:length(theFiles)
...
...
READ = dlmread(fullFileName,'',1,0);
allData(end+1:end+size(READ,1), :) = READ;
end
Second, your fprintf() command isn't correct. You probably want something like this:
fprintf('%s (%d)\n',baseFileName, k);
Once you've read in all your data and stored it in 'allData', you can plot columns like this
plot(allData(:,2)) %Plotting column 2
If you'd like to plot data from each file individually, put the plotting function within the for-loop. That would look something like this.
for k = 1:length(theFiles)
...
...
READ = dlmread(fullFileName,'',1,0);
plot(READ(:,2)); %plotting column 2
end
7 Comments
Mr. 206
on 22 Aug 2018
You could do that within a loop.
for k = 1:length(theFiles)
...
...
READ = dlmread(fullFileName,'',1,0);
figure();
c = 0;
for j = 1: 2 : size(READ,2)
c = c+1;
subplot(ceil(size(READ,2)/2), 1, c)
plot(READ(:,j))
hold on
plot(READ(:,j+1))
end
end
Mr. 206
on 22 Aug 2018
Adam Danz
on 22 Aug 2018
"...and plot them in a single file". I interpreted that to mean you want all of the subplots on 1 figure (which, as you can see, is really crowded). You could space the subplots differently (see "help subplot") or you could spread them out onto different figures.
I don't have your data so I don't know what is causing the error. I believe my code assumes you have an even number of columns.
Mr. 206
on 23 Aug 2018
Mr. 206
on 23 Aug 2018
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!