0
I need to save data from a file .txt
to open in excel. I can save the data, so that each loop is saved one below the other, but I can’t save in columns.
The first two columns are the same, which is different are the last two columns.
Function:
for i = 1:9
vi = vi+(i+10-i);
misv = (C1.*(1-exp(-C2.*si))-C3.*si).*exp(-C4.*vi);
misvc = (C1.*(1-exp(-C2.*si))-C3.*si).*mi0.*exp(-C4.*vi);
TempA = [si; Fsi; misv; misvc];
FilenameA = strcat(Filename,' - Slip Function','.txt');
fid = fopen(FilenameA{1},'at+');
fprintf(fid, 'Slip Slip_Function Slip Slip_Function_Dry Slip_Function_Cont \n');
fprintf(fid,'------------------\n');
fprintf(fid,'%.3f %.3f %.3f %.3f\n',TempA);
fprintf(fid,'------------------\n');
fclose(fid);
Filing cabinet .txt
:
Slip Slip_Function Slip Slip_Function_Dry Slip_Function_Cont
------------------
0,000 0,000 0,000 0,000;
0,010 0,224 0,208 0,187;
0,020 0,399 0,370 0,333;
0,030 0,536 0,497 0,448;
0,040 0,643 0,597 0,537;
0,050 0,727 0,674 0,607;
Slip Slip_Function Slip Slip_Function_Dry Slip_Function_Cont
------------------
0,000 0,000 0,000 0,000;
0,010 0,224 0,193 0,173;
0,020 0,399 0,344 0,309;
0,030 0,536 0,461 0,415;
0,040 0,643 0,554 0,498;
0,050 0,727 0,626 0,563;
Hello Guto, Thanks for the help, I went through the routine you sent and she is saving a single line. the first two lines are two parameters that are used to calculate the others, as I could not save all parameters in the same file each time the loop runs it saves the two columns again but they only need to be saved in the first loop.
– Juliano Cardoso
@Julianocardoso, I did not understand your comment. Did it work or not? Your initial problem was columns, and the file of my way saves the amount I understood you wanted from columns: 2 initial plus the results.
– Guto
Deculpe Guto, it really worked, I was wrong to put the parameters of my function in his routine.. Thank you very much.....
– Juliano Cardoso
Guto let me ask you another question, when I use dlmwrite the result of the file is this way 1 2 1 2 2 4 3, i.e., all results are written in a row, using the fprintf(fid,'%.5f %.5f %.5f n',Temp_as_dt); it writes three columns but it fills the data row by row, ie it uses all data from column 1 of the matrix Temp_as_dt to fill the 1 rows of the 3 columns then goes to the second row until complete the three columns until finishing the data of the first column of the Matrix Temp_as_dt ai starts with the data of the second column.
– Juliano Cardoso
@Julianocardoso Since you are a novice user, it is worth the recommendation. A comment - in general - is not the place for new questions. A comment such as the first ones are relevant, as they can change/clarify the question/answer. The latter does not require further explanations not necessarily relevant to your initial question. One option is to modify the question, but in this case you would use the answer as the question, which completely changes the question/answer focus. I recommend a new question with an example, and put a link to this question to have the context.
– Guto
@Julianocardoso If you ask another question, put the link here because then I can take a look tb (but no promises to answer).
– Guto