Save file in columns

0

I need to save the data from a .txt file to open in excel. I can save the data, so that each loop is saved one below the other, but I can not save it in columns.

The first two columns are the same, what 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);

File .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;
    
asked by anonymous 10.12.2018 / 14:42

1 answer

0

If I understood what you want, you want to have only the two initial columns and then only have the data you generated in columns. To do this, one way is to create the data in just one array and save this array.

Example:

iii=9;
%initialize variables
tempALL=zeros(10,iii*2+2);
tempALL(:,1)=(1:10)'; %primeira coluna
tempALL(:,2)=(2:2:20)'; %segunda coluna

%escreva elas na formato que você que ter a saida.
for a=1:iii;
    tempALL(:,a*2+1)=tempALL(:,1)*a; % aqui são os dados da terceira coluna
    tempALL(:,a*2+2)=tempALL(:,2)*a; % quarta coluna.
    %perceba o aumento no indice da matrix que está sendo salvo os dados
end
%veja que salvo fora do loop, acessos a arquivos em loop em geral não é uma boa pratica.
dlmwrite('myFile.txt',tempALL,'delimiter','\t','precision',3)

See the options of dlmwrite .

Looking at my output file, the names do not appear. One solution is you can create the file the way you are creating, but with the names sorted in just one line. Save only the names and close the file. Use dlmwrite with the option -append and you will have the names and data. I can put a code for this another time.

If not, leave a comment that I can try to improve.

    
10.12.2018 / 15:59