Questions tagged [matlab-struct]

For questions about the MATLAB structure datatype.

A structure is a datatype in MATLAB. It is different from cells and arrays in that it uses field names, and within fields one can store other data, also of type struct, cell, array, etc.

MathWorks has a tutorial on accessing data in a structure array.

The basic function to create one is, among others, struct.

145 questions
1
vote
1 answer

Create structure fieldnames from array of numbers

I have a dataset that I would like to categorise and store in a structure based on the value in one column of the dataset. For example, the data can be categorised into element 'label_100', 'label_200' or 'label_300' as I attempt below: %The labels…
Hefaestion
  • 203
  • 1
  • 8
1
vote
1 answer

Create structure with field names from an array

Below I have a snippet of code that I am using to create a structure with field names that are defined in the array 'field_names'. This seems like a very clunky way of creating the structure. Is there a better way that I can do this in one line?…
Hefaestion
  • 203
  • 1
  • 8
1
vote
1 answer

Structure array dimensions

Is there a difference between a 1x3 structure array and a 3x1 structure array? From what I can see, there doesn't appear to be but I'm not entirely sure.
Jay P
  • 175
  • 6
1
vote
1 answer

Transform struct/array of arrays into a single array in Matlab

I have a Matlab struct that contains arrays. Specifically it is allocated like this: info(27).field1 = []; info(27).field2 = []; info(27).field3 = []; It's filled via a loop % here simplified for your convenience for i = 1:27 info(i).field1 =…
Honeybear
  • 2,928
  • 2
  • 28
  • 47
1
vote
1 answer

Matlab Array of structures: string not working

I am reading an input from a file and importing it into my data to run in Matlab: parts = strread(tline,'%s','delimiter',';') employee(i).name = parts(1); employee(i).salary= str2double(parts(2)); Then I try to print it out: for…
Gerry Woodberg
  • 336
  • 1
  • 11
1
vote
1 answer

Loading excel files in structures

I am working on a small project which requires huge amount of data to be imported into matlab for further processing. I have currently 15 excel files and each file has 8 sheets. What I want is to make a parent structure in which I want load each…
Muhammad
  • 67
  • 1
  • 1
  • 7
1
vote
2 answers

Concatenating structure elements

For example test = struct('one', [1;2;3], 'two', [4;5;6]); I would like to vertically concatenate the vectors in the struct test. For example, if it were defined as a cell array instead test = {[1;2;3], [4;5;6]}, I could do vertcat(test{:}).…
Alex
  • 15,186
  • 15
  • 73
  • 127
1
vote
1 answer

Why MATLAB keeps consuming memory when setting fields of a preallocated struct?

I'm reading frames of an AVI movie and doing some calculations on its frames. This is a part of my code: clear; clc; mov = mmreader('traffic.avi'); vidHeight = mov.Height; vidWidth = mov.Width; nFrames = mov.NumberOfFrames; patchsize =…
saastn
  • 5,717
  • 8
  • 47
  • 78
1
vote
2 answers

Arrays to array of struct. MATLAB

I have three vectors centers, radiuses, metrics all Nx1 (centers is Nx2, but it is not a problem at all). And I want to convert them into vector Nx1 of structures where each structure has fields: center, radius, metric and corresponding values of…
Vladimir
  • 179
  • 9
1
vote
1 answer

Exporting a cell structure from Matlab to Excel

I have a cell structure which has <1*40 struct> inside it. Every structure has the same field names (each having 12 field names and respective values). I want to Export this cell Array into an Excel file such that all the field names become the…
Aakash Sehgal
  • 171
  • 1
  • 2
  • 12
1
vote
2 answers

MATLAB: Copying variables from table to struct based on certain criteria

I have a table column1data = [11; 22; 33]; column2data = [44; 55; 66]; column3data = [77; 88; 99]; rows = {'name1', 'name2', 'name3'}; T = table(column1data, column2data, column3data); T.Properties.RowNames = rows column1data column2data…
Arthur Tarasov
  • 3,517
  • 9
  • 45
  • 57
1
vote
2 answers

Iterating over Matlab struct

I have a 1x1 Matlab struct with 15 fields results = RAR_no_compartments_2_0: [1x1 struct] RAR_no_compartments_2_1: [1x1 struct] RAR_no_compartments_2_10: [1x1 struct] RAR_no_compartments_2_11: [1x1 struct] …
CiaranWelsh
  • 7,014
  • 10
  • 53
  • 106
1
vote
1 answer

Matlab: get value from a struct with mixed capitalization of field names

I have a struct with about thousands of field names and corresponding values. The field names are mixed in capitalization but are unique as far as name is concerned. I need to look up for values. I know the field name for which I am looking for…
Zanam
  • 4,607
  • 13
  • 67
  • 143
1
vote
1 answer

How can I group variables from a mat file by name and collect them in a structure?

I'm reading in a mat file which has variables with a counter e.g. a1, a2, a3, b, c1 and c2. I want to put the data into a structure with field names "a", "b" and "c" where a=[a1;a2;a3], b=b and c = [c1; c2]. The algorithm needs to be able to do…
barbar
  • 701
  • 1
  • 5
  • 11
1
vote
2 answers

Remove data from struct bigger than a certain value

I have a struct, that's a <1x1 struct>, and I'm trying to edit a field in the struct based on the values. The field is called GeoDist_Actual and the struct is called GeoDist_str. The field GeoDist_Actual is a <262792x1 double>, and this is the code…
Pierson Sargent
  • 175
  • 2
  • 18