Creating multidimensional table from multidimensional array

조회 수: 26 (최근 30일)
Ali Tawfik
Ali Tawfik 2020년 5월 18일
편집: Ameer Hamza 2020년 5월 18일
Hi,
I have some 3D arrays, and I would like to obtain/create table for each dimension, I could do it but I wanna it to operate like in a for loop so it depends on how many dimension is the array,
Please any help, I am using MatLab 2016a
Also, how could I assign/change variable name :
Thanks,
clear all; clc; close all;
x(:,:,1)=1;
x(:,:,2)=2;
y(:,:,1)=3;
y(:,:,2)=4;
for i=1:2;
z(:,:,i)=table(x(:,:,i),y(:,:,i));
% x.Properties.VariableNames = {'x1','x2','y1','y2'};
end

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 5월 18일
편집: Ameer Hamza 2020년 5월 18일
Creating a 3D table is not yet allowed in MATLAB. Also, you cannot assign a table as an element of a simple array. A good way is to use a cell array where each of its cells contains a table.
x(:,:,1)=1;
x(:,:,2)=2;
y(:,:,1)=3;
y(:,:,2)=4;
z = cell(1,2);
for i=1:numel(z)
z{i}=table(x(:,:,i),y(:,:,i));
z{i}.Properties.VariableNames = {'x','y'};
end
You can then access the table values using variable names like this
z{1}.x % x column of first table
z{2}.y % y column of second table

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by