Printing repeating double header with dlmwrite and for loop
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (1)
DC
el 6 de Dic. de 2016
Categorías
Más información sobre Get Started with MuPAD en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!