MATLAB Answers

Defining multiple arrays at once?

74 views (last 30 days)
Xen
Xen on 19 Sep 2014
Edited: Kien Pham on 17 Sep 2018
I am writing a code which requires a few zero arrays of the same dimension for a summation process in a loop, and I was wondering if it is possible to define them all at once. For example, I want 3 vectors A to C
A=zeros(5,1);
B=zeros(5,1);
C=zeros(5,1);
How can this be replaced with one line (if possible)? Thanks.

Accepted Answer

Guillaume
Guillaume on 19 Sep 2014
[A, B, C] = deal(zeros(5,1));
  4 Comments
Kien Pham
Kien Pham on 17 Sep 2018
@Stephen Colbeldick: I was trying to deal one cell to multiple cell arrays. While trying to clarify my question to you, I was able to answer my own question by looking up deal.
Thank you anyway for your response. It really helps me think about how I write my questions to the Community next time.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by