필터 지우기
필터 지우기

how to make a script that plots all data loaded from to different repositories?

조회 수: 1 (최근 30일)
hello! I must plot alot of data, so I would like to know if there is a way how to make a script that loop over all the data files in two different repositories and when the files have a similar number at the end of their names just plot them together. I hope I have made myself clear? any suggestions are very welcomed! thank you!

채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 31일
You can use fileparts() to separate the directory and extension from the file specification. After that, the best way to determine the file number (for matching) would depend upon how the file names are structured.

추가 답변 (2개)

Ano
Ano 2017년 5월 31일
편집: Ano 2017년 5월 31일
I have written the following code, and I have made the files in both repositories with the same name, I get the data from the first repository but I get the error unable to read file from the second repository. any suggestions ???!!
addpath('..\data\f1files')
addpath('..\data\f2files')
direction1 = '..\data\f1files'
direction2 = '..\data\f2files'
filepattern = fullfile(direction1,'*.mat' );
theFiles = dir (filepattern);
for i=1: length(theFiles)
baseFileName = theFiles(i).name;
fullFileName1 = fullfile(direction1,baseFileName);
fullFileName2 = fullfile(direction2,baseFileName);
F1= load (fullFileName1)
plot(F1.fdata);
hold on;
F2= load(fullFileName2)
plot(F2.fdata);
legend('f1' , 'f2');
end
  댓글 수: 3
Ano
Ano 2017년 5월 31일
but why the code fails in loading the data from the second repository ??I mean I only get the data from the first repository ploted!!! any suggestions ??!!
Walter Roberson
Walter Roberson 2017년 5월 31일
You asked "when the files have a similar number at the end of their names just plot them together" . Perhaps the file names in the two directories are not identical, just matching in some part of interest to you. You should post a file name from the first directory and the corresponding file name from the second directory.

댓글을 달려면 로그인하십시오.


Ano
Ano 2017년 6월 1일
problem solved! just add the following line to the code, thank you very much !
filepattern2 = fullfile(direction2,'*.mat');

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by