persona.nome='Marco' persona = struct with fields: nome: 'Marco' persona.cognome='Caliari' persona = struct with fields: nome: 'Marco' cognome: 'Caliari' persona.age=35 persona = struct with fields: nome: 'Marco' cognome: 'Caliari' age: 35 persona.matrice=[1,2;3,4] persona = struct with fields: nome: 'Marco' cognome: 'Caliari' age: 35 matrice: [2×2 double] persona.cognome ans = 'Caliari' help struct struct Create or convert to structure array. S = struct('field1',VALUES1,'field2',VALUES2,...) creates a structure array with the specified fields and values. The value arrays VALUES1, VALUES2, etc. must be cell arrays of the same size, scalar cells or single values. Corresponding elements of the value arrays are placed into corresponding structure array elements. The size of the resulting structure is the same size as the value cell arrays or 1-by-1 if none of the values is a cell. struct(OBJ) converts the object OBJ into its equivalent structure. The class information is lost. struct([]) creates an empty structure. To create fields that contain cell arrays, place the cell arrays within a VALUE cell array. For instance, s = struct('strings',{{'hello','yes'}},'lengths',[5 3]) creates the 1-by-1 structure s = strings: {'hello' 'yes'} lengths: [5 3] Example s = struct('type',{'big','little'},'color','red','x',{3 4}) See also isstruct, setfield, getfield, fieldnames, orderfields, isfield, rmfield, deal, substruct, struct2cell, cell2struct. Reference page for struct Other functions named struct persona.cognome ans = 'Caliari' x=linspace(0,1,11); y=cos(x); xx=linspace(0,1,21); yy=spline(x,y,xx); plot(x,y,'*',xx,yy) plot(x,y,'*',xx,yy,'-o') pp=spline(x,y) pp = struct with fields: form: 'pp' breaks: [1×11 double] coefs: [10×4 double] pieces: 10 order: 4 dim: 1 pp.breaks ans = Columns 1 through 4 0 0.1000 0.2000 0.3000 Columns 5 through 8 0.4000 0.5000 0.6000 0.7000 Columns 9 through 11 0.8000 0.9000 1.0000 pp.coefs ans = 0.0214 -0.5035 0.0002 1.0000 0.0214 -0.4971 -0.0999 0.9950 0.0422 -0.4907 -0.1987 0.9801 0.0569 -0.4780 -0.2955 0.9553 0.0726 -0.4609 -0.3894 0.9211 0.0871 -0.4392 -0.4794 0.8776 0.1011 -0.4130 -0.5646 0.8253 0.1131 -0.3827 -0.6442 0.7648 0.1275 -0.3488 -0.7174 0.6967 0.1275 -0.3105 -0.7833 0.6216 a=pp.coefs(1,:) a = 0.0214 -0.5035 0.0002 1.0000 plot(x,y,'*',xx,yy,'-o',xx,a(1)*xx.^3+a(2)*xx.^2+a(3)*xx+a(4)) A=pp.coefs; x=pp.breaks; mkpp(x,A) ans = struct with fields: form: 'pp' breaks: [1×11 double] coefs: [10×4 double] pieces: 10 order: 4 dim: 1 b=pp.coefs(11,:); {Index in position 1 exceeds array bounds (must not exceed 10). } b=pp.coefs(10,:); plot(x,y,'*',xx,yy,'-o',xx,b(1)*xx.^3+b(2)*xx.^2+b(3)*xx+b(4)) plot(x,y,'*',xx,yy,'-o',xx,b(1)*(xx-x(10)).^3+b(2)*(xx-x(10)).^2+b(3)*(xx-x(10))+b(4)) help spline spline Cubic spline data interpolation. PP = spline(X,Y) provides the piecewise polynomial form of the cubic spline interpolant to the data values Y at the data sites X, for use with the evaluator PPVAL and the spline utility UNMKPP. X must be a vector. If Y is a vector, then Y(j) is taken as the value to be matched at X(j), hence Y must be of the same length as X -- see below for an exception to this. If Y is a matrix or ND array, then Y(:,...,:,j) is taken as the value to be matched at X(j), hence the last dimension of Y must equal length(X) -- see below for an exception to this. YY = spline(X,Y,XX) is the same as YY = PPVAL(spline(X,Y),XX), thus providing, in YY, the values of the interpolant at XX. For information regarding the size of YY see PPVAL. Ordinarily, the not-a-knot end conditions are used. However, if Y contains two more values than X has entries, then the first and last value in Y are used as the endslopes for the cubic spline. If Y is a vector, this means: f(X) = Y(2:end-1), Df(min(X))=Y(1), Df(max(X))=Y(end). If Y is a matrix or N-D array with SIZE(Y,N) equal to LENGTH(X)+2, then f(X(j)) matches the value Y(:,...,:,j+1) for j=1:LENGTH(X), then Df(min(X)) matches Y(:,:,...:,1) and Df(max(X)) matches Y(:,:,...:,end). Example: This generates a sine-like spline curve and samples it over a finer mesh: x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,'o',xx,yy) Example: This illustrates the use of clamped or complete spline interpolation where end slopes are prescribed. In this example, zero slopes at the ends of an interpolant to the values of a certain distribution are enforced: x = -4:4; y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0]; cs = spline(x,[0 y 0]); xx = linspace(-4,4,101); plot(x,y,'o',xx,ppval(cs,xx),'-'); Class support for inputs x, y, xx: float: double, single See also interp1, pchip, ppval, mkpp, unmkpp. Reference page for spline diag([1,2,3,4])+diag([5,6,7],1)+diag([8,9,10],-1) ans = 1 5 0 0 8 2 6 0 0 9 3 7 0 0 10 4 spdiags([[1;2;3;4],[5;6;7;NaN],[NaN;8;9;10]],[0,1,-1],4,4) ans = (1,1) 1 (2,1) NaN (1,2) 6 (2,2) 2 (3,2) 8 (2,3) 7 (3,3) 3 (4,3) 9 (3,4) NaN (4,4) 4 full(spdiags([[1;2;3;4],[5;6;7;NaN],[NaN;8;9;10]],[0,1,-1],4,4)) ans = 1 6 0 0 NaN 2 7 0 0 8 3 NaN 0 0 9 4 full(spdiags([[1;2;3;4],[NaN;5;6;7],[8;9;10;NaN]],[0,1,-1],4,4)) ans = 1 5 0 0 8 2 6 0 0 9 3 7 0 0 10 4 spdiags([[1;2;3;4],[NaN;5;6;7],[8;9;10;NaN]],[0,1,-1],4,4) ans = (1,1) 1 (2,1) 8 (1,2) 5 (2,2) 2 (3,2) 9 (2,3) 6 (3,3) 3 (4,3) 10 (3,4) 7 (4,4) 4 spdiags([[1;2;0;4],[NaN;5;6;7],[8;9;10;NaN]],[0,1,-1],4,4) ans = (1,1) 1 (2,1) 8 (1,2) 5 (2,2) 2 (3,2) 9 (2,3) 6 (4,3) 10 (3,4) 7 (4,4) 4 spdiags([[1;2;3;4],[NaN;5;6;7],[8;9;10;NaN]],[0,1,-1],4,4) ans = (1,1) 1 (2,1) 8 (1,2) 5 (2,2) 2 (3,2) 9 (2,3) 6 (3,3) 3 (4,3) 10 (3,4) 7 (4,4) 4 x = rand (1, 4); y = rand (1, 4); spline (x, y) ans = struct with fields: form: 'pp' breaks: [0.1270 0.8147 0.9058 0.9134] coefs: [3×4 double] pieces: 3 order: 4 dim: 1 pp=spline (x, y) pp = struct with fields: form: 'pp' breaks: [0.1270 0.8147 0.9058 0.9134] coefs: [3×4 double] pieces: 3 order: 4 dim: 1 pp1=spline_notaknot(x,y); pp.coefs-pp1.coefs ans = 1.0e-10 * -0.0034 0.0023 -0.0006 0 -0.0171 -0.0011 0.0003 0 -0.5002 0.0364 -0.0003 0 spline_notaknot(1,2) {Array indices must be positive integers or logical values. Error in spline_notaknot (line 13) d0 = [h(2:n - 3) / 6; (h(n-2)-h(n-1))/6; 0]; } spline(1,2) {Error using chckxy (line 42) There should be at least two data points. Error in spline (line 53) [x,y,sizey,endslopes] = chckxy(x,y); } spline_notaknot([1,2],[2,4]) {Array indices must be positive integers or logical values. Error in spline_notaknot (line 13) d0 = [h(2:n - 3) / 6; (h(n-2)-h(n-1))/6; 0]; } spline([1,2],[2,4]) ans = struct with fields: form: 'pp' breaks: [1 2] coefs: [2 2] pieces: 1 order: 2 dim: 1 ppder {Undefined function or variable 'ppder'. } diary 'off'