MATLAB Answers

# How to put a vector in a matrix?

조회 수: 34(최근 30일)
kyana shayan 2015년 12월 8일
댓글: Guillaume 2016년 2월 13일
Hi everyone, I want a matrix with one row and 6 columns, which 3 of the first columns are vectors. like this: CoupleElement={ (1,2) , (1,4) , (3,5), 6,7,8 } can anyone help me please? I don't know how to put a vector in an element of a matrix. Thanks for your time

댓글을 달려면 로그인하십시오.

### 채택된 답변

John BG 2015년 12월 8일
CE= {(1,2) (1,4) (4,5) 6 7 8} does not work. Start with correct definition of the matrix CE={[1 2] [1 4] [4 5] 6 7 8}
1. read: CE(1) is still a cell, but CE{1} is the initial vector of doubles
2. write: CE(6)={9}
3. append: CE={CE magic(4)} now if you want to read CE(1) is the previous initial cell and CE(2) is magic(4)
back to your initial matrix:
CE={[1 2] [1 4] [4 5] 6 7 8}
kill 2nd row CE(2)=[]
before taking cells head on it really helps to go through the MATLAB help search for 'Add cells to cell array' and carry on reading the related links
crack on
John
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
Guillaume 2016년 2월 13일
Huh, what's this about? (and why is it popping up two months later?)
The mathematical and scientific languages are extremely accurate languages where each word have a well defined meaning. If you start swapping the meaning of terms, people are going to misunderstand you and you're just going to waste time.
Cell arrays and matrices are very different entities in matlab, from the way they are stored in memory, through the way in which you access the elements, to the set of functions you can use on them.
We often get new users of matlab coming here and asking questions where they use the wrong terms in their question, leading to wasted posts before we figure out what they really mean. The answer to 'I want to sum the rows of my matrix m' is very different if m is really a matrix (answer: use sum(m)) or actually a cell array (answer: in general, you can't).

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!