在MATLAB中同时定义多个变量? [英] Define multiple variables at the same time in MATLAB?
本文介绍了在MATLAB中同时定义多个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道MATLAB是否可以做到这一点,我纯粹是出于代码美观的目的,但是MATLAB可以同时创建两个变量吗?
I don't know if MATLAB can do this, and I want it purely for aesthetics in my code, but can MATLAB create two variables at the same time?
示例
x = cell(4,8);
y = cell(4,8);
有没有办法编写类似于以下代码的代码:
Is there a way to write the code something similar to:
x&y = cell(4,8);
推荐答案
使用逗号分隔的列表可在表达式的左侧获取多个变量.
Use comma-separated lists to get multiple variables in the left hand side of an expression.
您可以使用Deal()将多个分配放在一行中.
You can use deal() to put multiple assignments one line.
[x,y] = deal(cell(4,8), cell(4,8));
用一个输入调用它,所有输出得到相同的值.
Call it with a single input and all the outputs get the same value.
[x,y] = deal( cell(4,8) );
>> [a,b,c] = deal( 42 )
a =
42
b =
42
c =
42
这篇关于在MATLAB中同时定义多个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文