fprintf applied to variable

8 Ansichten (letzte 30 Tage)
Espen
Espen am 10 Nov. 2011
function balancepoint=findbalpoint(A)
weight=0;
i=1;
while weight<sum(A)/2
weight=weight+A(i);
if weight>sum(A)/2
diff=sum(A)/2-weight;
end
i=i+1;
end
note='function assumes constant density'
meter=1/A(i)
string=fprintf('if you subtract %.2f meter from the number %d meter of the bar u get balancepoint', meter, i)
balancepoint=string;
I wonder why the string above is saved as 80 and how you can save the fprintf as ans or as a variablestring
This is what happened when I ran it in matlab:
>> findbalpoint(matrix)
note =
function assumes constant density
meter =
0.1250
if you subtract 0.13 meter from the number 8 meter of the bar u get balancepoint
string =
80
ans =
80

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 10 Nov. 2011
I think you are looking for sprintf and fprintf
doc sprintf

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by