Export data to text file

I have the following information From the code I created
Beam number = 2
Weight = 56.01
Maximum stress = 169.34
I want export the above that to a text file called BestBeam.txt
It should look like this
Beam Data: 2
Weight: 56.01 Kg
Maximum Stress: 169.43 MPa
Can someone tell help me

7 件のコメント

Rik
Rik 2019 年 5 月 6 日
What have you tried so far? It shouldn't be too hard to find an example of how to write a file.
LINDO MTSWENI
LINDO MTSWENI 2019 年 5 月 6 日
I used this dlmwrite('BestBeam.txt',[BeamNumber; Weight; MaximumStress],' ')
It gives me : 2 56.01 169.34
Walter Roberson
Walter Roberson 2019 年 5 月 6 日
fopen fprintf fclose
Walter Roberson
Walter Roberson 2019 年 5 月 6 日
It is possible to write your desired output with dlmwrite(), but it is not intended to do that and the method for tricking it into doing so are harder to implement and less understandable than simply using fopen() / fprintf() / fclose()
LINDO MTSWENI
LINDO MTSWENI 2019 年 5 月 6 日
Thank you . this is the data i calculated using other methods in my code
MaximumuStress=169.34
Weight=56.01
BeamNumber=2
this is what i did:
data = [BeamNumber; Weight; MaximumStress];
Units = cell2mat(units);
labels = {'Beam Number','Weight','Maximum Stress'};
fid = fopen('BestBeam.txt','wt');
for b = 1:3;
fprintf(fid,'%6s: ',labels{b});
fprintf(fid,'%.2f\n',data(b));
end
fclose(fid);
it works perfectly and this is what the output text file look like
Beam Number: 2.00
Weight: 56.01
Maximum Stress: 169.34
my problem is that the final output should have units to the values i.e:
Beam Number: 2.00
Weight: 56.01 Kg
Maximum Stress: 169.34 MPa
can you help me on how i can add these units next to the values .
Thank you
Walter Roberson
Walter Roberson 2019 年 5 月 6 日
Where is your cell array that contains the unit to use for each element?
LINDO MTSWENI
LINDO MTSWENI 2019 年 5 月 6 日
I'm so sorry I forgot to put it in...I looks like this units={ ' ','Kg',' MPa'};

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

質問済み:

2019 年 5 月 6 日

コメント済み:

2019 年 5 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by