필터 지우기
필터 지우기

creating cell array

조회 수: 1 (최근 30일)
Tor Fredrik Hove
Tor Fredrik Hove 2011년 10월 23일
I would like to create a cell array with 1 row and two columns and in each column it is a columnvector of 5 elements in the first 5 numbers in the second 5 characters. This was my attempt:
>> cellarray2too1={5.3; 2.2; 3.3; 4.4; 1.1, 'a'; 'b'; 'a'; 'a'; 'b'} ??? Error using ==> vertcat CAT arguments dimensions are not consistent.

채택된 답변

Image Analyst
Image Analyst 2011년 10월 23일
Look at your statement. After each semicolon it tries to make a new row in your cell array. So the first row has 5.3. The next row has 2.2. The next row has 3.3. The next row has 4.4. Each of those rows has one thing that goes into one cell. Now look at the next row. You have 1.1, 'a' and this is two things. It's trying to make that row be two cells when each of your prior rows was only one cell. It can't concatenate a two cell row to a columnar array of one-cell rows. That's why you got the error. You could either fix it like andrei suggested, or use this alternative:
cellarray2too1={5.3; 2.2; 3.3; 4.4; 1.1; 'a'; 'b'; 'a'; 'a'; 'b'}
depending on exactly what you want to have. Note I put "1.1; 'a'" so that it is now two rows of one cell each instead of one row of two cells. Think of a cell array as a grid of buckets on the floor. You can arrange the buckets into any rectangular array shape you want. And you can toss almost anything you want into each bucket. But your syntax tried to create a row of two buckets when all the other buckets were in a single line. You were trying to do this:
5.3
2.2
3.3
4.4
1.1, 'a'
'b'
'a'
'a'
'b'
and that is not allowed.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2011년 10월 23일
cellarray2too1={[5.3; 2.2; 3.3; 4.4; 1.1],[ 'a'; 'b'; 'a'; 'a'; 'b']}

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by