필터 지우기
필터 지우기

How to pass a cell to a function?

조회 수: 7 (최근 30일)
Negar
Negar 2014년 12월 21일
댓글: Image Analyst 2014년 12월 21일
Hello,
I have a cell array of size (1344X1). each cell element contains a matrix: first row: 22x40 double, second row 22X52 double,, third row 22X112 double, and so on (My data points are all 22-dimentional). Now I want to pass all elements of the cell array at the same time to a function. I tried the following, but it seems to pass the cell emoluments one by one.
[centers, membership_idx] = myKmeans(data(:,1));
  댓글 수: 1
Guillaume
Guillaume 2014년 12월 21일
It's not very clear what you want to do. All the elements of the cell array is basically the cell array itself, so why can't you pass the cell array?
What does your function take as inputs?

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

답변 (1개)

Image Analyst
Image Analyst 2014년 12월 21일
편집: Image Analyst 2014년 12월 21일
You do not have any 22 dimensional arrays. Your cell array is a 1-D array. Inside each cell is a 2-D array with 22 rows and some variable number of columns. You might find the FAQ useful.
Since your cell array has only 1 column and 1344 rows, data(:,1) would be the first column, but since it's a column vector it would pass all cells in your cell array, not just one cell. So what you said happens does not agree with what you described. It should be passing the whole cell array but that's not the way it's usually done. Usually to pass a whole array, you don't attach parentheses and indexes to it. You just use the name of the cell array all by itself.
Let's say your cell array is called "data" and you want to pass the entire cell array into some custom function you wrote called "myKmeans()". To do that you'd do:
[centers, membership_idx] = myKmeans(data);
  댓글 수: 3
Negar
Negar 2014년 12월 21일
Oh I just realized that when I use cell2mat, the problem is solved:
%meanstore = cell2mat(data(:,1)');
%[centers, membership_idx] = myKmeansmain(meanstore);
But Im still wondering why it is not possible to pass the cell column, as it is, to the function?
Image Analyst
Image Analyst 2014년 12월 21일
You can pass the cell array to the function. The problem came inside the function when you tried to sum something. Evidently the sum() function does not like cell arrays and you need to extract the matrix with {} or use cell2mat().

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by