how can concat cell array with array?

for example i have cell arrays s{i} ,i want s{i}s pose in one column and another vector like f=[3 4 .....] pose in another column .

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 19일

0 개 추천

s=[s num2cell(yourarray)]

댓글 수: 1

fatemeh
fatemeh 2013년 10월 19일
but this give this error: Error using horzcat CAT arguments dimensions are not consistent.
Error in prog (line 56) y= [s1{h} num2cell(f(h))]

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

Cedric
Cedric 2013년 10월 19일
편집: Cedric 2013년 10월 19일

0 개 추천

s = {1; 2; 3; 4} ; % Column cell array.
f = [10 20 30 40] ; % Row numeric array.
c = [s, num2cell(f.')] ;

댓글 수: 4

fatemeh
fatemeh 2013년 10월 19일
but this gives this error: Error using horzcat CAT arguments dimensions are not consistent.
Error in prog (line 56) y= [s1{h} num2cell(f(h))]
Cedric
Cedric 2013년 10월 19일
What is the size of s1{h}? Both Azzi and I understood that you wanted to concatenate a cell array and a numeric array based on your question. It seems that you want to concatenate the content of cell h of cell array s1 and element h of numeric array f, which is not the same operation.
Use SIZE and CLASS on the different objects involved in your expression to get a better understanding of what they are and about their size.
fatemeh
fatemeh 2013년 10월 19일
h is the index for a for loop ,each s1{h} is the 7*4 array and f(h) produce vector at each time, i want these are both in a one matrix... h =1000
Cedric
Cedric 2013년 10월 19일
If you want to concatenate horizontally the content of cells of s1 and the output of f (assuming that f is a function), their number of columns must match. This means that you have to check that f outputs a 7x1 vector (and not 1x7, otherwise you have to transpose it).

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

카테고리

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

질문:

2013년 10월 19일

댓글:

2013년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by