Help on txt file

조회 수: 1 (최근 30일)
I3JM
I3JM 2019년 8월 22일
댓글: Guillaume 2019년 8월 23일
Hello,
I am pretty new to Matlab, so excuse my bad understanding of its natural behaviour... :D
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
  댓글 수: 3
I3JM
I3JM 2019년 8월 23일
Unfortunately, that doesnt work neither... Tried both
Guillaume
Guillaume 2019년 8월 23일
Unfortunately, that doesnt work neither... Tried both
I'm not sure who this is addressed to. I wasn't offering a solution ... yet, since as I've said the desired text output is not consistent with the input (printing a row vector, when the input is a column). Until you've clarified if the inconsensistency is on purpose, I'm not going to offer a solution that may not do what's needed.

댓글을 달려면 로그인하십시오.

채택된 답변

AdamG2013468
AdamG2013468 2019년 8월 22일
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');
  댓글 수: 1
AdamG2013468
AdamG2013468 2019년 8월 22일
you can modify the second line,
writecell(Variablen_wert, 'temp.txt', Delimiter, ' ')
If you don't want to print the comma delimiters.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by