How to print status
Afficher commentaires plus anciens
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.
Réponses (2)
Steven Lord
le 17 Juin 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 commentaire
madhan ravi
le 17 Juin 2020
+1 for that SF line , been looking for it for days!!
madhan ravi
le 17 Juin 2020
Modifié(e) : madhan ravi
le 17 Juin 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
2 commentaires
Rafael Zanetti
le 17 Juin 2020
madhan ravi
le 17 Juin 2020
list = ["success", "failure"];
s = list((m<=0) + 1);
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!