필터 지우기
필터 지우기

Find the file number when a condition meets

조회 수: 3 (최근 30일)
Tesla
Tesla 2021년 10월 21일
댓글: Tesla 2021년 10월 24일
I have for example 300 files (data1.dat data2.dat data3.dat ...), and inside every file I have for example two columns X and Y.
I want to find the number (index) of the files where this condition meets:
50< X <100 and 60 <Y< 100
To get something like that:
Files = [ 10 46 230 299 ]

채택된 답변

John D'Errico
John D'Errico 2021년 10월 21일
편집: John D'Errico 2021년 10월 21일
Beginners do this sort of thing. They are tentative, almost afraid to use MATLAB, even when they think they need to. So they leave their data in files. Break your problem, ANY problem too large for you to figure it out, break it into small subproblems.
Problem 1: READ IN YOUR DATA. Bring in each file into MATLAB. Until you do this, you will constantly need to be accessing each file, dealing with the names of the files, etc. If the varius files have the same number of rows, then put it all into one 3-dimensional array. If they have different numbers of rows, then put the data into a cell array. Since you will be doing something else afterwards with this data, surely you need to read it into MATLAB eventually. Do it immediately, the first thing you do.
Problem 2: Once your data is in MATLAB, now the test is simple. It will depend on how you store the data, but there are simple ways to perform the test that would take at most a few lines of code to do. You will use find in the end to determine the indices of the datasets that fit all of the necessary rules.
If the problems above are still too large, then break them down more deeply. Eat a programming elephant, even a small one, one byte at a time.
  댓글 수: 1
Tesla
Tesla 2021년 10월 24일
Thank you for this talk, I will accept it as a solution

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by