Renaming a struct in v2020b
Mostra commenti meno recenti
Hi,
I am currently writting code to detect peaks in a signal.
The data is pre-recorded in a series of dynamically named .mat files (i.e patient_1, patient_2 etc.) I want to try and move away from dynamic naming.
I want the user to select a .mat file say 'patient_1' for example and rename it to 'patient_X'. This should make it easier to write generic functions and apply them.
I have tried a similar method to inputing as one would with csv and other files with uigetfile:
[fileName, pathName] = uigetfile('*.mat'); % only looks for .mat files
pat_data = readstruct(fullfile(pathName,fileName)) ; % concat file path and type
However the new readstuct (2020b) function does not allow .mat data, only .XML so this does not work.
I have also tried just renaming the stuct like a standard variable:
pat_XXX = load(fileName) ; % Rename the struct
however I then get a 1x1 struct called pat_XXX with the orignal stuct inside it.
I really think this should be an easy task but I cannot figure out where I am going wrong and a look for answers has only provided how to change struct feildnames
Kind Regards,
Christopher
Risposta accettata
Più risposte (1)
Walter Roberson
il 15 Nov 2020
pat_data = load(fullfile(pathName, fileName));
save(newFileName, 'pat_data', '-struct')
Though you could also consider
movefile( fullfile(pathName, fileName), newFileName );
1 Commento
Christopher McCausland
il 16 Nov 2020
Categorie
Scopri di più su Workspace Variables and MAT Files in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!