Hello,
I am trying to split my table at ceratin rows. I have several Data sets, so the row numbers are not always the same. I have stored the rows where the table should split in an array. If, for example, my array is [500 900 1200], then I want the table to be split as following:
T1=row 1-499
T2=row 500-899
T3=row 900-1199
T4=row 1200-end
I have tried doing this with a for loop for the middle section (T2, T3) but this returns the table together and not split. Any ideas? :)
% array with the rows where the table should be split is Split_Rows
for a=length(Split_Rows)-1
k=Split_Rows;
SplitTable=FlowData([k:k(a+1)-1],:);
end

2 件のコメント

Stephen23
Stephen23 2019 年 5 月 23 日
Using numbered variables is a sign that you are doing something wrong.
Rather than using numbered variables, you should use simple and efficient indexing, exactly as madhan ravi's answer shows.
JessHmann
JessHmann 2019 年 5 月 23 日
編集済み: JessHmann 2019 年 5 月 23 日
Okay, thank you for the tipp!

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

 採用された回答

madhan ravi
madhan ravi 2019 年 5 月 23 日

2 投票

v=[1 500 900 1200];
% ^--appended 1 at the beginning
Splittable=cell(numel(v)-1,1);
for k=2:numel(v)
Splittable{k-1}=T(v(k-1):v(k)-1,:);
end
Splittable{k}=T(v(end):end,:) % where T is your table

4 件のコメント

JessHmann
JessHmann 2019 年 5 月 23 日
Thank you very much!!
JessHmann
JessHmann 2019 年 5 月 23 日
The Tables are noe stored in the array 'Splittable'. Is there a way to extract them automatically (without doing it like this NewDataT1=Splittable{1,1})?
madhan ravi
madhan ravi 2019 年 5 月 23 日
Don't try to name your variable dynamically!! Keep them as is (cell array) you can access them via loop.
Mandeep Kaur
Mandeep Kaur 2021 年 9 月 16 日
How we can write the new table after spilitting it??
Thank you

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

製品

リリース

R2019a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by