Creating a multidimensional table
조회 수: 112 (최근 30일)
이전 댓글 표시
I'd like to create a multidimensional table. For example a 3D table with 10 stacked 3x3 matrices.
I tried with this code, but it doesn't work:
R = zeros(3,3,10);
T = table(R);
Thank you in advance.
댓글 수: 8
Benjamin Azrieli
2020년 11월 12일
@WalterRobinson If I wanted to access a certain range in the double under one of the variables, how would I do so using your example? This page does not seems to help: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html
Benjamin Azrieli
2020년 11월 12일
In case anyone wants to know, I figured it out:
T.data_statistics(row #, n, m) , where n and m are the row and column dimensions, respectively, of the double under the variable name 'data_statistics'
답변 (3개)
per isakson
2018년 12월 29일
With R2018b
>> R = zeros(3,3,10);
>> T = table(R);
>> T
T =
3×1 table
R
_______________
[1x3x10 double]
[1x3x10 double]
[1x3x10 double]
>>
What do you mean by "it doesn't work"
댓글 수: 8
per isakson
2018년 12월 31일
편집: per isakson
2018년 12월 31일
mergevars was "Introduced in R2018a."
I learn a lot tonight :)
Walter Roberson
2018년 12월 31일
R2015b experiment:
>> load data_statics
>> T1 = table(data_statics);
T2 = table(label_statics);
T = table(T1,T2);
>> T
T =
T1 T2
___________ ___________
[1x1 table] [1x1 table]
Mike D.
2019년 7월 9일
T = table(T1,T2,T3) only works if all three tables have exactly the same number of columns AND exactly the same number of rows, and all columns are the same data type. If I had a 1000 tables, it would be nice if Matlab could index them:
T(1) = T1;
T(2) = T2;
for i = 1:1000
T(i) = readtable(sprintf('file%d.dat', i), opts);
end
댓글 수: 1
Walter Roberson
2019년 7월 9일
Use cell array.
T = cell(1000,1);
T{1} = T1;
T{2} = T2;
for i = 1:1000
T{i} = readtable(sprintf('file%d.dat', i), opts);
end
Remember that for tables, the syntax T(i) is a shortcut for T{:,i} so for arrays of tables T(i) would be an ambiguous syntax unless arrays of tables were a different datatype.
Mike D.
2019년 7월 9일
Works great, thanks. When I plot all thousand tables, each having thousands of rows and multiple columns, I couldn't do it with a one-liner such as:
plot(T{:}{:,1},T{:}{:,2})
Instead, I had to use a for-loop:
for i = 1 : numel(T)
plot(T{i}{:,1},T{i}{:,2})
plot(T{i}.Longitude, T{i}.Latitude)
end
But it works, thanks.
댓글 수: 1
Walter Roberson
2019년 7월 9일
You can use cellfun.
hold on
cellfun(@(t) plot(t.Longitude, t.Latitude), T);
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!