Printing repeating double header with dlmwrite and for loop
Show older comments
I'm trying to print a '.dat' file with the code below that produces a repeating double header 776 times. The value at the end of each header line should change by +1.
for ii = 103:878
dlmname3 = 'Input_commands.dat';
header={'*Elset, elset=CALIBRATED_210_FINAL_VOLUME' num2str(ii)};
for ik = 1:776
header2={'*Include, input=Final_element_' num2str(ik) '.dat'};
end
dlmwrite(dlmname3, header,'delimiter','','-append');
dlmwrite(dlmname3, header2,'delimiter','','-append');
fclose all;
end
I would like this code to produce:
*Elset, elset=CALIBRATED_210_FINAL_VOLUME103
*Include, input=Final_element_1.dat
*Elset, elset=CALIBRATED_210_FINAL_VOLUME104
*Include, input=Final_element_2.dat
*Elset, elset=CALIBRATED_210_FINAL_VOLUME105
*Include, input=Final_element_3.dat
and so on up volume 878 and final_element_776...
However it is currently producing:
*Elset, elset=CALIBRATED_210_FINAL_VOLUME103
*Include, input=Final_element_776.dat
*Elset, elset=CALIBRATED_210_FINAL_VOLUME104
*Include, input=Final_element_776.dat
*Elset, elset=CALIBRATED_210_FINAL_VOLUME105
*Include, input=Final_element_776.dat
etc...
I've tried a few variations but it's never quite right. I think the problem is (ik) finishes before the second iteration of (ii) hence 776 showing up on all even lines. I know I could normally do it with one loop but I need the alternate lines to use and have different values.
I think I am missing something simple for the solution so apologies in advance for that but also a thank you in advance for any help you might be able to provide!
Accepted Answer
More Answers (1)
DC
on 6 Dec 2016
Categories
Find more on Get Started with MuPAD in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!