Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Русский


table2struct

convert a table into a struct

Syntax

st = table2struct(t)
st = table2struct(t, "ToScalar", %t)

Arguments

t

table object

st

structure

Description

table2struct converts a table into a structure. The data of t can be heterogeneous. Each variable in t becomes a fieldanmes in st. If the size of t is [m,n] then st will be m x 1 structure array with n fieldnames. If t is a table with row names, then the data is lost.

st = table2struct(t, "ToScalar", %t) converts the table t to a scalar structure st, i.e, if the size of t is [m, n] then st will have n fieldnames and each fieldname will have m rows.

Examples

Code = ["AF"; "NA"; "OC"; "AN"; "AS"; "EU"; "SA"];
NameContinent = ["Africa"; "North America"; "Oceania"; "Antarctica"; "Asia"; "Europe"; "South America"];
Area = [30065000; 24256000; 7687000; 13209000; 44579000; 9938000; 17819000]; // in km2
NumberCountry = [54; 23; 14; %nan; 47; 45; 12]; 
LifeExpectancy = [60; 78; 75; %nan; 72; 75; 74]; // in years

t = table(Code, NameContinent, Area, NumberCountry, LifeExpectancy, ...
    "VariableNames", ["Code", "NameContinent", "Area", "NumberCountry", "LifeExpectancy"])
st = table2struct(t)

st = table2struct(t, "ToScalar", %t)

See also

  • table — create a table from variables
  • matrix2table — convert a matrix into a table

History

ВерсияОписание
2024.0.0 Introduction in Scilab.
Report an issue
<< table2matrix Timeseries/Table table2timeseries >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:55:12 CEST 2024