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 Kommentare

Rik
Rik am 6 Mai 2019
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 am 6 Mai 2019
I used this dlmwrite('BestBeam.txt',[BeamNumber; Weight; MaximumStress],' ')
It gives me : 2 56.01 169.34
Walter Roberson
Walter Roberson am 6 Mai 2019
fopen fprintf fclose
Walter Roberson
Walter Roberson am 6 Mai 2019
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 am 6 Mai 2019
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 am 6 Mai 2019
Where is your cell array that contains the unit to use for each element?
LINDO MTSWENI
LINDO MTSWENI am 6 Mai 2019
I'm so sorry I forgot to put it in...I looks like this units={ ' ','Kg',' MPa'};

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 6 Mai 2019

Kommentiert:

am 6 Mai 2019

Community Treasure Hunt

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

Start Hunting!

Translated by