Extract Tables from within a cell

조회 수: 35 (최근 30일)
HabenG
HabenG 2021년 11월 27일
답변: Walter Roberson 2021년 11월 27일
I have a bunch of tables saved within a cell, each table with two columns. How do i extract each table from the cell?
The table is attached.

채택된 답변

Chunru
Chunru 2021년 11월 27일
s = load("Tables")
s = struct with fields:
Tables: {[1512×2 table] [1512×2 table] [1512×2 table] [1512×2 table] [1512×2 table] [1512×2 table] [1512×2 table]}
% i-th tables
i = 1;
t = s.Tables{i}
t = 1512×2 table
Px Var2 ______ _______ 10.9 0.74314 10.9 0.74314 10.91 0.75497 10.88 0.72697 10.88 0.72692 10.87 0.72287 10.87 0.72287 10.9 0.74314 10.87 0.72287 10.84 0.72796 10.84 0.72796 10.87 0.72287 10.925 0.77663 10.98 0.87914 11.059 0.99377 11.095 1.0041

추가 답변 (2개)

KSSV
KSSV 2021년 11월 27일
load('Tables.mat');
T = cellfun(@table2array,Tables,'UniformOutput',false) ;
iwant = cell2mat(T') ;

Walter Roberson
Walter Roberson 2021년 11월 27일
Tables{1}
Tables{2}
and so on.
If you wanted to put the results together into a cell array so that you could work with this in a loop or something like that... then the cell array would be exactly the same as what you already have.
I have the suspicion that you want to extract them into individual variables and that you want that done automatically no matter how many entries are in the cell. If so... don't . http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
If you are fixed to exactly 7 entries, then you could use
[T1, T2, T3, T4, T5, T6, T7] = Tables{:};
... but you probably shouldn't... at least not unless you have better names available. Perhaps
[flux_monday, flux_tuesday, flux_wednesday, flux_thursday, flux_friday, flux_saturday, flux_sunday] = Tables{:};
Something like that would be reasonable.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by