How to print status
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I am writing a program that I need the output be print "Success" or "Failure" on a table of 4 columns, my program is that:
function m = margin_of_safety(F,sigma);
m = F - sigma;
table = [F;sigma;m];
fprintf(' F sigma m \n');
fprintf('%4d %10.2f %10.2f \n',table);
end
And I need the test be this way,but I want replace the checks for text as I had explained

I thank you.
0 Kommentare
Antworten (2)
Steven Lord
am 17 Jun. 2020
I recommend not using table as a variable name as table is the name of a data type in MATLAB.
Let's use your sample data.
>> sampleData = [72 60 12; 72 80 -8; 82 60 22; 82 80 2];
Build a table array using your sample data.
>> T = array2table(sampleData, 'VariableNames', ["F", "sigma", "m"]);
Turn the m variable from your table T into a categorical array with value "failure" when T.m is not greater than 0 and "success" when T.m is greater than 0.
>> SF = categorical(T.m > 0, [false, true], ["failure", "success"]);
Now add this variable to the table. I'm using a table variable name that is not a valid MATLAB identifier, which is allowed in a table since release R2019b. Use a different name if you're using an earlier release.
>> T.("Success/Failure") = SF
T =
4×4 table
F sigma m Success/Failure
__ _____ __ _______________
72 60 12 success
72 80 -8 failure
82 60 22 success
82 80 2 success
Let's get some data from T.
T(T.("Success/Failure") == "failure", :)
1 Kommentar
madhan ravi
am 17 Jun. 2020
Bearbeitet: madhan ravi
am 17 Jun. 2020
function m = margin_of_safety(F,sigma);
m = F - sigma;
s = ["success", "failure", "success", "success"];
TablE = [F;sigma;m;s];
fprintf(' F sigma m %s\n');
fprintf('%4d %10.2f %10.2f \n',TablE);
end
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!