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 个评论

What have you tried so far? It shouldn't be too hard to find an example of how to write a file.
I used this dlmwrite('BestBeam.txt',[BeamNumber; Weight; MaximumStress],' ')
It gives me : 2 56.01 169.34
fopen fprintf fclose
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()
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
Where is your cell array that contains the unit to use for each element?
I'm so sorry I forgot to put it in...I looks like this units={ ' ','Kg',' MPa'};

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by