reading multiple .mps files in a loop

3 vues (au cours des 30 derniers jours)
vishakha nagarajan
vishakha nagarajan le 9 Fév 2022
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 commentaires
Mathieu NOE
Mathieu NOE le 9 Fév 2022
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

Connectez-vous pour commenter.

Réponses (1)

Nihal
Nihal le 2 Jan 2024
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

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by