Confusion with adding to cell array

2 ビュー (過去 30 日間)
Harold
Harold 2013 年 5 月 20 日
コメント済み: Salma Hassan 2020 年 4 月 2 日
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 日
linesegs(2,:) = mat2cell(B, 1, [2 2]);
  6 件のコメント
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 日
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
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 5 月 20 日
Note that is not "the next row".

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by