reading multiple .mps files in a loop

조회 수: 3 (최근 30일)
vishakha nagarajan
vishakha nagarajan 2022년 2월 9일
답변: Nihal 2024년 1월 2일
I have about 100 .mps files of raw data and need to process this info(they are all stored in a folder). I want to read each file, extract a specific section of each of the files (from 1:4 coloums), find the maximum value in each of this extracted data (for each file) and store this max data separately. How can I go about this?
Thanks!
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2022년 2월 9일
hello
example for excel files below , adapt to your own needs :
fileDir = pwd;
sheet = 2; % data must be retrieved from sheet #2
S = dir(fullfile(fileDir,'*.xlsx')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order (what matlab does not) , see FEX :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
for k = 1:length(S)
data = xlsread(fullfile(fileDir, S(k).name),sheet); % or use a structure (S(k).data ) to store the full data structure
% your code here
end

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

답변 (1개)

Nihal
Nihal 2024년 1월 2일
Hi Vishakha,
I understand you are trying to read .mps files using loop and find the maximum. I would like to suggest the use of MATLAB's mpsread function to facilitate the reading of your .mps files. To assist you further, I've prepared a sample code snippet that you might find useful as a starting point:
% Define the directory containing your .mps files
fileDir = pwd; % Current working directory
% Retrieve a list of .mps files in the specified directory
S = dir(fullfile(fileDir, '*.mps'));
% Loop through each file in the directory
for k = 1:length(S)
% Read the data from the current .mps file
data = mpsread(fullfile(fileDir, S(k).name));
% Insert your custom processing code here
end
Please tailor the placeholder comment "Insert your custom processing code here" with the specific code that applies to the structure and requirements of your MPS files.
For a more comprehensive understanding of how to utilize the mpsread function effectively, I recommend visiting the following MATLAB documentation page: https://www.mathworks.com/help/optim/ug/mpsread.html. This resource should provide you with valuable insights and examples to guide you through the process.
I hope this helps

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by