将“布尔值”转换为“布尔值” MATLAB 中的字符串到数组

发布于 2024-12-26 02:12:48 字数 200 浏览 1 评论 0原文

我需要将布尔索引字符串转换为一个数组,如下所示:

convert('11001') = [1 2 5]
convert('0000') = []
convert('001') = [3]

我不控制生成字符串的函数。

有什么想法可以以优雅的方式做到这一点吗?我已经用循环完成了它,但不知何故它看起来不对。

I need to convert a string of boolean indices into an array which would look like this:

convert('11001') = [1 2 5]
convert('0000') = []
convert('001') = [3]

I don't control the function which produces the string.

Any ideas to do this in an elegant way? I already did it whith a loop but it looks wrong somehow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初吻给了烟 2025-01-02 02:12:48
function y = convert(s)
y = find(s == '1');
function y = convert(s)
y = find(s == '1');
压抑⊿情绪 2025-01-02 02:12:48

这是将每个字符转换为数字的变体。

function y = convert(s)
y = find(str2num(s')')

Here's a variation that converts each character to a number.

function y = convert(s)
y = find(str2num(s')')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文