I have a cell array with the structure as such,
linesegs = [1x2 double] [1x2 double]
I do some calculations on with some other data that is sent to a function within the current program using a function handle. This results in the following structure within the function.
B = [0 0 1 1];
I want insert this array in the next row of linesegs. Basically B would be split into two cells, one containing [0 0] and the other [1 1].
Everything that I've tried seems to be failing.

 채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 20일

0 개 추천

linesegs(2,:) = mat2cell(B, 1, [2 2]);

댓글 수: 6

Harold
Harold 2013년 5월 20일
편집: Harold 2013년 5월 20일
I have actually tried this and I keep getting this error,
Error using mat2cell (line 107) Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [1 1].'
I should also note, that after the calculations are finished in the function the output is returned as a 1x1 cell.
Harold
Harold 2013년 5월 20일
I just figured this out. After the function, I convert the cell to a matrix. Then I convert the matrix back to a cell and I get the format I need.
[1x2 double] [1x2 double]
My function is called by means of a function handle that I created, which points to a function that does the calculations I need. The function handle is called by arrayfun.
Walter Roberson
Walter Roberson 2013년 5월 21일
You should consider using cellfun() instead of arrayfun()
Image Analyst
Image Analyst 2013년 5월 21일
Why are you messing around with the complication of a cell array anyway? As I see it, a regular numerical matrix would handle these line segment coordinates just fine, and be a lot simpler.
Harold
Harold 2013년 5월 21일
편집: Harold 2013년 5월 21일
I will have to post up my program that I'm working on since I am having some more problems with it as well. I well edited this post with the link in a bit.
Salma Hassan
Salma Hassan 2020년 4월 2일
could some help me in this issue above

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

추가 답변 (1개)

Amith Kamath
Amith Kamath 2013년 5월 20일

0 개 추천

This should work:
a = {[0 0], [0 0]}
b = [1 2 3 4]
a{1} = b(1:2) %choose the first two elements from b and assign to first in a.
a{2} = b(3:4) %choose third and fourth

카테고리

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

제품

태그

질문:

2013년 5월 20일

댓글:

2020년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by