필터 지우기
필터 지우기

assign vector to cell

조회 수: 28 (최근 30일)
MatteP
MatteP 2016년 5월 26일
답변: Jos (10584) 2016년 5월 26일
I have a vector k, whose length is N.
I have created an empty cell(N,M)=New
Is there a clever way to assign the values of the vector to the first column of the cell? I mean something whose outcome is the same as
for j=1:N
New{j,1}=k(j)
end
Thanks

채택된 답변

Stephen23
Stephen23 2016년 5월 26일
편집: Stephen23 2016년 5월 26일

추가 답변 (2개)

Jos (10584)
Jos (10584) 2016년 5월 26일
num2cell is just the loop you wrote hidden behind a function. Nothing to gain there, I would say.
Just for fun, you could also abuse arrayfun:
k = 10:10:100
C = arrayfun(@(x) x, k, 'un',0)

Andrei Bobrov
Andrei Bobrov 2016년 5월 26일
편집: Andrei Bobrov 2016년 5월 26일
New = num2cell(k)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by