フィルターのクリア

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..

2 ビュー (過去 30 日間)
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
  2 件のコメント
Adam Danz
Adam Danz 2018 年 8 月 22 日
Your goal is clear, the code is helpful, but you never stated the problem you're facing.
Mr. 206
Mr. 206 2018 年 8 月 22 日
I loaded all the txt files but can not be able to plot them. any suggestion please? I am a novis in this field.

サインインしてコメントする。

採用された回答

Julie
Julie 2018 年 8 月 22 日
myFolder = '/home/ali/IDT';
% Get a list of all files in the folder with the desired file name pattern.
theFiles = dir(fullfile(myFolder, '*.txt'));
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)
for j=1:6
figure %replace with "hold on" if you want them all on the same graph
plot(READ(:,2*(j-1)+1),READ(:,2*(j-1)+2))
end
end
  1 件のコメント
Mr. 206
Mr. 206 2018 年 8 月 22 日
Great! Actually i wanted the subplot function to have all the graph together in one one file. Other then that accept my apology if i am too silly, can you please explain the plot command that you used? Thanks again

サインインしてコメントする。

その他の回答 (1 件)

Adam Danz
Adam Danz 2018 年 8 月 22 日
(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 件のコメント
Mr. 206
Mr. 206 2018 年 8 月 23 日
I added some code to store all the plots in a specific folder. But it returns an error like (error: 'export_fig' undefined near line 22 column 10)
Mr. 206
Mr. 206 2018 年 8 月 23 日
編集済み: Mr. 206 2018 年 9 月 12 日
l=0
l=l+1;
initialFigure = sprintf('figure_%d.jpg',l);
% Specify some particular, specific folder:
fullFigure = fullfile('/home/ali/ign_figures', initialFigure);
figure(l);
addpath(pwd)
export_fig(fullFigure);
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by