How can i display variable name on message box?
显示 更早的评论
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
采纳的回答
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 个评论
Thank you so much, its work!
My pleasure!
If my Answer solved your problem, please Accept it!
i try another method to show the min ans,by table
A=40;
B=6;
C=10;
D=21;
E=17;
F=22;
Name = {'A';'B';'C';'D';'E';'F'};
Value = [A;B;C;D;E;F];
T = table(Name,Value)
rows = min(Value);
vars = {'Name'};
Final = T(rows,vars)
why the final table will not show the name of minimum value, it show the F or 'Row index exceeds table dimensions'.
Notice that Star Strider used
[minvar,idx] = min(varvctr);
and then used the idx value.
You have used
rows = min(Value);
which returns the minimum value but not its position.
I still not understand how can i show it,
Name
____
'B'
if i change
rows = min(Value);
to
[minvar,idx] = min(Value);
it still cannot show what i want :(
Thanks Walter, its work!!!
Thank you Walter!
Fast asleep here (UTC-7) during that exchange.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
