Load multiple files one by one into a subfolder or Extract data from strut
Afficher commentaires plus anciens
Hi,
How can I load multiple files from a subfolder without merging them into a strut. ?
or
I have a .mat files in a folder I have loaded them using the command below.
matpath = 'C:..\..sol_file\';
matfiles = dir(fullfile(matpath ,'*.mat'));
Please how can I extract the files separately ?
6 commentaires
Dyuman Joshi
le 19 Oct 2023
Modifié(e) : Dyuman Joshi
le 19 Oct 2023
The general consensus is to read them as a structure or a cell array and use indexing to access data - TUTORIAL: Why Variables Should Not Be Named Dynamically (eval)
Why do you want to extract the files separately?
"I have a .mat files in a folder I have loaded them using the command below."
The code you show does not LOAD any file data into MATLAB memory.
"Load multiple files one by one into a subfolder..."
That does not make any sense: file data can be loaded into memory. Files are not loaded "into a subfolder". You could certainly copy or move files to a folder.
"...or Extract data from strut"
What is the expected output?
University
le 19 Oct 2023
Modifié(e) : University
le 19 Oct 2023
University
le 19 Oct 2023
University
le 19 Oct 2023
You can extract the imported file data into its own structure array, which will make the data easier to access. This assumes that each scalar structure in the DATA field has exactly the same fields (which so far you have not told us).
Given your structure S, after the file importing loop do this:
Z = [S.data];
After that you can trivially use indexing to access the data, e.g. for the 2nd file:
S(2).name % filename
Z(2).helloworld % the fields which so far you have not told us what they are called
Z(2).otherfields
Z(2).etcetcetc
Do NOT try to magically create all of that data as separate variables in the workspace. There be dragons.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!