how can i assign a column in a cell array -a vector

I have a 1*n cell array C an a matrix M n*8. i have to assign each column of C [1.....n] a vector of 8 values that are the columns of M.
z=size(M,1);
C=cell(1,z);
for i=1:z
v=M(i,:);
c(1,i)=v;
end
error = "Conversion to cell from double is not possible."
How to remove this error??
can i use mat2cell.I am not able to understand how to use it.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 19일
편집: Azzi Abdelmalek 2014년 11월 19일
M=rand(4,8) % Example
out=num2cell(M,2)'
%If you want to do it with your for loop, use curly bracket C{1,i}=v; or C(1,i)={v};
z=size(M,1);
C=cell(1,z);
for i=1:z
C{1,i}=M(i,:); % or C(1,i)={M(i,:)};
end

추가 답변 (0개)

카테고리

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

질문:

2014년 11월 19일

댓글:

2014년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by