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
2
votes
1 answer

Operations on two struct arrays in matlab

I have struct and array of structs in matlab like: s.name = 'pop'; s.val1 = 2.3; s.val2 = 4.3; q = repmat( s, 5, 5 ); Is it possible to do operations in vectorial-way? %// Something like this? q(:,:).val1 = q(:,:).val1 + q(:,:).val2 *…
qloq
  • 689
  • 1
  • 5
  • 15
2
votes
5 answers

Is there a way to remove all but a few desired fields from a struct in MATLAB?

So I have several structs that contains data that is used is a dozen or so scripts. The problem is that for each script I only need a handfull of variables and the rest I can ignore. I am using a massive amount of data (gigs of data) and MATLAB…
Fred
  • 1,054
  • 1
  • 12
  • 32
2
votes
3 answers

MATLAB: collect from array of structs

The output of eg >>w = whos; returns an array of structs. I would like to construct an array whose elements are the scalars from a particular field name in each struct. The most obvious way of doing this doesn't return an array as I want, but each…
second
  • 28,029
  • 7
  • 75
  • 76
1
vote
3 answers

How to put a struct in a struct

I just started using Matlab, and I absolutely despise (or not properly understand), the typesystem (or lack thereof). Why does this not work ? I just want structs within structs (in a recursive function) K>> d = struct('op',1,'kids',[]) d =…
rafalio
  • 3,928
  • 4
  • 30
  • 33
1
vote
1 answer

How to access attributes of a Python class as one would access fields of a Matlab structure in an iterative context

In Matlab, let's consider a structure "structure" and a list of fields "list_of_fields". structure = struct; list_of_fields = ["a","b","d"]; % Some specific fields of the structure and not all of them for field = list_of_field structure.(field)…
Valery
  • 25
  • 5
1
vote
1 answer

Create Dynamic structure variables and save them

For my program input is a csv file with some variable names and their values. | var name | value | | -------- | -------------- | | a.b | 345 | | a.c._0_.field1 | 322 | | a.c._0_.field2 | 5 …
Anonymous
  • 336
  • 3
  • 23
1
vote
4 answers

Provide variable argument list

I have a function which accepts a variable number of input variables. The problem is, the number of input arguments I'm going to provide varies. As such, I store all the arguments in a structure: function grandAvg(datafiles) % Load up all averaged…
eykanal
  • 26,437
  • 19
  • 82
  • 113
1
vote
1 answer

Having trouble accessing a structure field in MATLAB

I have a structure in MATLAB. When I try to access a field, I see this displayed: [4158x5 double] How do I get the array itself?
john c
  • 13
  • 1
  • 3
1
vote
2 answers

Access elements of a vector in a structure array MATLAB

I have a structure which contains two fields one of them contains vectors,example: myStruct(1).f1 = val1; myStruct(1).f2 = [elt1 elt2 elt3]; I want to find the indices of the elements of myStruct where elt1 == valA and elt2 == valB
Afaf
  • 59
  • 5
1
vote
1 answer

Checking two MATLAB structs as equal even if field contents are transposed

I need to check if two MATLAB structs (all fieldnames and values) are equal. Both of these structs are structs of structs. Occasionally, these structs are equal except for one thing: the field values in one struct are the transpose of the field…
Mayou
  • 8,498
  • 16
  • 59
  • 98
1
vote
1 answer

How to access certain elements in Matlab structure array

I am working on a Matlab project that connects with Thingsboard website. I use webread function to get the response from the server which sends information as JSON. When I send a request to get the users' information, I should get the information in…
Ebra
  • 35
  • 6
1
vote
1 answer

Extract fields from Structure Array to put into another Structure Array

I have a structure array with a large number of fields that I don't care about, so I want to extract the limited number of fields I DO care about and put it into a separate structure array. For a structure array of size one, I've done this by…
Rek
  • 45
  • 4
1
vote
1 answer

Flexible struct name without switch

For my code I need a changeable structure. Depending on a counter the structure should add additional fields. All fields shall be flexible and may have different values. Currently, I use a switch-condition. For transparency I would like to change…
bg_rohm
  • 11
  • 1
1
vote
3 answers

How can I merge redundant fields within a structure?

I have a data set with multiple fields of which several of the fields are different names for equivalent properties. I have rescaled and adjusted the data so that the quantities are comparable and want to merge them into a single field. As a toy…
Goods
  • 225
  • 2
  • 10
1
vote
1 answer

Matlab: how to concatenate the fields of a structure array?

I have a structure array in which every value is a number, I would like to concatenate these structures into a single one. Example: S is structure array and every element has the same structure S(1).a = 1 S(1).b.c = 1 S(1).b.d = 2 S(2).a =…
Hugo Trentesaux
  • 1,584
  • 1
  • 16
  • 30