Creating multidimensional table from multidimensional array

30 views (last 30 days)
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

Answers (1)

Ameer Hamza
Ameer Hamza on 18 May 2020
Edited: Ameer Hamza on 18 May 2020
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

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!