如何在MATLAB中从网格网格创建字符串单元格?

编程入门 行业动态 更新时间:2024-10-24 07:25:58
本文介绍了如何在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创建a和b的值:

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

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

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

推荐答案

您可以使用 INT2STR 和 STRCAT 函数:

params = strcat({'-a '},int2str(a(:)),{' -b '},int2str(b(:)));

更多推荐

如何在MATLAB中从网格网格创建字符串单元格?

本文发布于:2023-11-23 04:43:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620130.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   字符串   单元格   如何在   MATLAB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!