如何在MATLAB中从网格网格创建字符串单元格? [英] How can I create a cell of strings out of a meshgrid in MATLAB?

查看:74
本文介绍了如何在MATLAB中从网格网格创建字符串单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库函数,它将参数作为文本字符串(这是带有MATLAB前端的通用C库).我想用一组这样的参数来调用它:

I have a library function that takes parameters as a text string (it's a general C library with a MATLAB frontend). I want to call it with a set of parameters like this:

'-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创建ab的值:

I'm creating the values of a and b with meshgrid:

[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

现在我想以某种方式将其放入字符串单元格中:

And now I want to somehow put these into a cell of strings:

params = {'-a 0 -b 1'; -a 0 -b 2';等等...}

params = {'-a 0 -b 1'; -a 0 -b 2'; etc...}

我尝试使用sprintf,但这只能将它们连接起来

I tried using sprintf, but that only concatenates them

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

除了循环遍历ab之外,如何创建所需的单元格?

Other than looping over a and b, how can I create the desired cell?

推荐答案

您可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆