MATLAB: Help on txt file

txt

Hello,
I am pretty new to Matlab, so excuse my bad understanding of its natural behaviour… 😀
I want to create a txt file from my workspace, so I tried:
A = [38;70;102;134;166];
B = [10];
C =[10];
D = [0];
Variablen = {'A =', 'B =', 'Umdrehungen =', 'C =', 'D = '};
Variablen_wert = [A;
B;
C;
D;];
log(2,:) = str2cell(Variablen_wert);
log(1,:) = Variablen;
fid = fopen('temp.txt','wt');
fprintf(fid,'%-4s %d\n',log{:});
fclose(fid);
The obvious problem is, A is a matrix, while the other Variables dont have the same size. I tried to convert them into a string, but that doesnt work as well.
In the end it hopefully should look like this:
A = 38 70 102 134 166
B = 10
C = 10
D = 0
Maybe you can help me on this 🙂 thank you very much

Best Answer

Just make one combined cell, then use the function writecell().
Variablen_wert = {'A =' [38 70 102 134 166];'B =' [10];'C =' [10]};
writecell(Variablen_wert, 'temp.txt');