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
John BG 2015년 12월 8일

0 개 추천

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

Guillaume
Guillaume 2015년 12월 8일
To be perfectly clear, it is not possible to have a matrix in which the elements are vectors (or matrices, or arrays). By definition, matrix elements are scalar.
A cell array on the other hand can have any kind of elements. The distinction is not just semantics. The syntax is different, the function that work on one usually don't work on the other, and the memory layout and speed of access are vastly different.
John BG
John BG 2016년 2월 13일
Prego Guillaume, often terms defined in general language dictionaries become outdated, especially in science. The description 'rectangular' you find in English dictionaries is no more the general description of mathematical matrices and arrays, but a specific case.
Just think of for instance of:
A triangular matrix, still a matrix, isn't it?
a 'step' in spheric coordinates (a ball)
a 'rectangle' on a spheric plane, do you still call it a rectangle?
a microwave guide, some are rectangular some are cylindrical
the vertices around a dodecahedron ..
Let's do our best to supply answers, not to open encyclical debates, shall we?
John
Guillaume
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).

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 12월 8일

댓글:

2016년 2월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by