How do I rename each individual item in a column in one function?
3 次查看(过去 30 天)
显示 更早的评论
I have a structure which has 15 fields with various columns. The first column is titled label and has the 15 conditions in it. I manually set these as before they were all called 'Undefined' and realised I could change each one with the function D.trials(1).label = "Single_L_M' and then repeat all the way till D.trials(15).label = "ISI200_R_M'. Is there a way in one function to rename the lables rather than 15 lines which I have currently:
D.trials(1).label = 'Single_L_M';
D.trials(2).label = 'Single_L_I';
D.trials(3).label = 'Single_R_I';
D.trials(4).label = 'Single_R_M';
D.trials(5).label = 'Double_L_M';
D.trials(6).label = 'Double_R_I';
D.trials(7).label = 'Double_R_M';
D.trials(8).label = 'ISI30_L_M';
D.trials(9).label = 'ISI30_L_I';
D.trials(10).label = 'ISI30_R_I';
D.trials(11).label = 'ISI30_R_M';
D.trials(12).label = 'ISI200_L_M';
D.trials(13).label = 'ISI200_L_I';
D.trials(14).label = 'ISI200_R_I';
D.trials(15).label = 'ISI200_R_M';
0 个评论
回答(1 个)
Adam Danz
2021-6-24
Create a list of the new names within a cell array and then use deal to distribute the list to the label fields.
Demo:
D.trials(1).label = 'Single_L_M';
D.trials(2).label = 'Single_L_I';
D.trials(3).label = 'Single_R_I';
newNames = {'ABC', 'DEF', 'GHI'};
[D.trials.label] = deal(newNames{:});
D.trials.label
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!