フィルターのクリア

how to add data into the cells of a cell array?

10 ビュー (過去 30 日間)
Paolo Ottonelli
Paolo Ottonelli 2020 年 1 月 15 日
コメント済み: Paolo Ottonelli 2020 年 2 月 3 日
Hi, I have a 3x1 cell Array X in which there are some data divided into 3 cells . I would like to add data to each cell in order to obtain an other cell array X1 that is in this way:
X={[2000:2001;2002];
[2003;2004;2005;2006;2007;2008];
[2010; 2011; 2012]}
X1={[2000:2001;2002;2003];
[2003;2004;2005;2006;2007;2008;2009;2010];
[2010; 2011; 2012]}
I wrote the following code but I would like to use indexing
X1={[X{1}(1):X{2}(1)];
[X{2}(1):X{3}(1)];
[X{3}(1):2019]}
  1 件のコメント
dpb
dpb 2020 年 1 月 15 日
You did use indexing; what is missing in your view?

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

回答 (1 件)

Jyothis Gireesh
Jyothis Gireesh 2020 年 1 月 20 日
I am assuming here that you want to create “X1” using the elements of the existing cell array “X”. The following code may be of help to you in achieving the desired result.
X1 = cell(3, 1);
X1 = {[X{1}; 2003]; [X{2}; 2009; 2010]; X{3}};
  1 件のコメント
Paolo Ottonelli
Paolo Ottonelli 2020 年 2 月 3 日
I solved in this way
function G=ver(X)
a=length(X);
G=cell(zeros);
if a>1
for i=1:(a-1)
G(i)={[X{i}(length(X{i})),(X{i+1}(1))]};
end
G=cellfun(@transpose,G','uniformOutput',false);
else
G={};
end

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

カテゴリ

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