Assigning multiple rows to a cell array in a loop
1 次查看(过去 30 天)
显示 更早的评论
Hello All, I'm trying to assign multiple rows to a preallocated cell array from a loop. The loop iterations are determined by the user. While the below script works, I don't like hard-coding the numbering, as some other versions of this code-section will have more than 20 lines - If I have to remove or add a line later it will be inconvenient. Note that there are other actions that occur during the loop which I've deleted to simplify things. I'm sure there's a better way to write this. Any suggestions?
%% variables necessary for test-running the script
VarName='ebsdNew';
phaseToPlot={'Forsterite','Enstatite','Diopside'};
%% actual script
%initialize the script
ScriptReturned{1}='%prepare to plot an EBSD map';
ScriptLoopOut=cell(7*size(phaseToPlot,2),1);
for i=1:size(phaseToPlot,2)
j=(i-1)*7;
%append action to the script variable
phase=char(phaseToPlot{i});
ScriptLoopOut{1+j}='%create a coloured orientation map';
ScriptLoopOut{2+j}=['oM = BungeColorKey(',VarName,'(''',phase,''').CS);'];
ScriptLoopOut{3+j}='%Get orientation colours from oM';
ScriptLoopOut{4+j}=['color = oM.orientation2color(',VarName,'(''',phase,''').orientations);'];
ScriptLoopOut{5+j}='hold on;';
ScriptLoopOut{6+j}=['plot(',VarName,'(''',phase,'''),color);'];
ScriptLoopOut{7+j}='hold off;';
end
ScriptReturned=[ScriptReturned;ScriptLoopOut];
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!