创建基于 matlab 列的函数

发布于 2024-12-28 06:29:32 字数 296 浏览 3 评论 0原文

有谁知道如何解决

删除重复项 - ** 仅当 按顺序出现重复项

Octave 中 ?公认的解决方案是使用 diff

Matlab 的 diff 似乎与 Octave 的行为不同,并且不接受字符。

任何想法表示赞赏。

Does anybody know how to solve

removing duplicates - ** only when the duplicates occur in sequence

in Octave? The accepted solution is using diff.

Matlab's diff seems to behave differently than the Octave's one and doesn't accept characters.

Any idea is appreciated.

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

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

发布评论

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

评论(1

北音执念 2025-01-04 06:29:32

您可以将字符转换为其 ASCII 代码,然后按给出的方式运行解决方案:

a = {'d' 'f' 'a' 'g' 'g' 'w' 'a' 'h'};
aa = cellfun(@(c) c-0, a);             %# convert to ASCII

idx = find(diff(aa) == 0);
a([idx idx+1]) = [];

You can convert the characters to their ASCII codes, then run the solution as given:

a = {'d' 'f' 'a' 'g' 'g' 'w' 'a' 'h'};
aa = cellfun(@(c) c-0, a);             %# convert to ASCII

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