![]() |
如何在MATLAB中从网格网格创建字符串单元格?
我有一个将参数作为文本字符串的库函数(这是带有MATLAB前端的通用C库)。我想用一组这样的参数来调用它:
'-a 0 -b 1' '-a 0 -b 2' '-a 0 -b 3' '-a 1 -b 1' '-a 1 -b 2' '-a 1 -b 3' 等等... 我正在用meshgrid创建a和b的值: [a,b] = meshgrid(0:5, 1:3); 产生: a = 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 b = 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 现在,我想以某种方式将它们放入字符串单元格中: 参数= {'-a 0 -b 1'; -a 0 -b 2';等等...} 我尝试使用sprintf ,但这仅将它们连接在一起 sprintf('-a %f -b %f', a ,b) ans = -a 0.000000 -b 0.000000-a 0.000000 -b 1.000000-a 1.000000 -b 1.000000-a 2.000000 -b 2.000000-a 2.000000 -b 3.000000-a 3.000000 -b 3.000000-a 4.000000 -b 4.000000-a 4.000000 -b 5.000000-a 5.000000 -b 5.000000-a 1.000000 -b 2.000000-a 3.000000 -b 1.000000-a 2.000000 -b 3.000000-a 1.000000 -b 2.000000-a 3.000000 -b 1.000000-a 2.000000 -b 3.000000-a 1.000000 -b 2.000000-a 3.000000 -b 1.000000-a 2.000000 -b 3.000000 除了遍历a和b ,如何创建所需的单元格? [B]回答:[/B] 您可以尝试使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/int2str.html"]INT2STR[/URL]和[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/strcat.html"]STRCAT[/URL]函数: params = strcat({'-a '},int2str(a(:)),{' -b '},int2str(b(:))); [url=https://stackoverflow.com/questions/2366680]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 11:05。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.