Assigning multiple rows to a cell array in a loop

4 ビュー (過去 30 日間)
Jessica Hiscocks
Jessica Hiscocks 2019 年 2 月 25 日
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 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by