Structure fieldname Rename by referring a .csv column
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi , I would like to rename the workspace structure fieldnames as per the desired names that are present in the column 2 of the .csv file.
The table looks like this
Fieldname DesiredName
____________ ____________
'Test_Sig0' 'Test_Sig_0'
'Test_Sig' 'Test_Sig_1'
'Junk_Sig' 'Junk'
'Junk_Sig_1' 'Junk1'
While structure looks like this
Test_Sig0: {3×2 cell}
Test_Sig: {3×2 cell}
As told earlier , I would like to replace the fieldname 'Test_Sig0' with Desired name referred from the csv, 'Test_Sig_0' and delete the fieldname 'Test_Sig0'.
3 Kommentare
Image Analyst
am 12 Jun. 2022
I've removed your flag. What is unclear. If it's your question, then make it clear with better explanations (don't flag it). If it's one of the Answers, ask the person to explain better.
Antworten (1)
Jan
am 12 Jun. 2022
Import the table. Then:
Fieldname = {'Test_Sig0', 'Test_Sig', 'Junk_Sig', 'Junk_Sig_1'};
DesiredName = {'Test_Sig_0', 'Test_Sig_1', 'Junk', 'Junk1'};
S = RenameField(S, Fieldname, DesiredName)
2 Kommentare
Jan
am 13 Jun. 2022
This is voodoo:
save('temp.mat', '-struct', 's'); % Save fields to a .mat file
clear all % Clear local variables (just for display purposes)
s=load('temp.mat');
clear all removes all loaded functions from the memory also and relaoding them fromthe slow disk is a massive waste of time.
I have posted a link to a function called RenameField already which does, what you want. Did you check it?
What is the purpose of this piece of code:
for j=1:numel(pos)
desired_ele=(model_test{pos})
end
desired_ele is overwritten in each iteration.
Does the posted code do, what you need or is there an open problem?
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!