フィルターのクリア

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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by