How can i display variable name on message box?

7 vues (au cours des 30 derniers jours)
yt man
yt man le 17 Fév 2017
Commenté : Star Strider le 18 Fév 2017
The case is:
in workspace, there are some variable name and corresponding value
for example
name=value
A=1
B=2
C=3
D=4
How to display the minimum value included variable name in message box: A=1

Réponse acceptée

Star Strider
Star Strider le 17 Fév 2017
Try this:
A=1;
B=2;
C=3;
D=4;
varcell = {'A','B','C','D'};
varvctr = [A B C D];
[minvar,idx] = min(varvctr);
msg = sprintf('%s = %d',varcell{idx},varvctr(idx));
msgbox(msg, 'Minimum: ')
  8 commentaires
yt man
yt man le 18 Fév 2017
Thanks Walter, its work!!!
Star Strider
Star Strider le 18 Fév 2017
Thank you Walter!
Fast asleep here (UTC-7) during that exchange.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by