对于普通的 MATLAB 数组,有没有类似 deal() 的东西? [英] Is there anything like deal() for normal MATLAB arrays?

查看:27
本文介绍了对于普通的 MATLAB 数组,有没有类似 deal() 的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
如何在 MATLAB 中进行多重赋值?

在处理元胞数组时,可以使用deal()函数将元胞赋值给输出变量,如:

When dealing with cell arrays, I can use the deal() function to assign cells to output variables, such as:

[a, b, c] = deal(myCell{:});

或者只是:

[a, b, c] = myCell{:};

我想对一个简单的数组做同样的事情,例如:

I would like to do the same thing for a simple array, such as:

myArray = [1, 2, 3];
[a, b, c] = deal(myArray(:));

但这行不通.有什么选择?

But this doesn't work. What's the alternative?

推荐答案

一种选择是首先使用 NUM2CELL:

One option is to convert your array to a cell array first using NUM2CELL:

myArray = [1, 2, 3];
cArray = num2cell(myArray);
[a, b, c] = cArray{:};

如您所见,您甚至不需要使用 DEAL 分发单元格内容.

As you note, you don't even need to use DEAL to distribute the cell contents.

这篇关于对于普通的 MATLAB 数组,有没有类似 deal() 的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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