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

Indexing/Accessing MATLAB nested structure

Hope, that I'm not creating a duplicate, but so far I didn't find the right answer for my problem. Let's say, we have the following structure(s): a(1).b = 1; a(1).x.y = 2; a(2).b = 3; a(2).x.y = 4; When I now try to get all values of b, I can…
Joojoo
  • 79
  • 5
2
votes
1 answer

How can I extract data members from stepinfo output in MATLAB?

When the stepinfo function is run on a transfer function (i.e. stepinfo(tf)) a typical result is: RiseTime: 52.2052 SettlingTime: 85.4916 SettlingMin: 0.9041 SettlingMax: 1.0012 Overshoot: 0.1192 Undershoot: 0 Peak: 1.0012 …
Jordan Arsenault
  • 7,100
  • 8
  • 53
  • 96
2
votes
1 answer

How do I find out in which strucutre my matlab variable is stored in?

I have raw data in a .mat format. The Data is comprised of a bunch of Structures titled 'TimeGroup_XX' where xx is just a random number. Each one of these structures contains a bunch of signals and their corresponding time steps. It looks something…
TheCake90
  • 23
  • 4
2
votes
2 answers

Vectorized extracting a list from MATLAB Cell Array

I have a two-index MATLAB Cell Array (AllData{1:12,1:400}) where each element is a structure. I would like to extract a list of values from this structure. For example, I would like to do something like this to obtain a list of 12 values from this…
M.T Frieze
  • 23
  • 2
2
votes
3 answers

find string in non-scalar structure matlab

Here's a non-scalar structure in matlab: clearvars s s=struct; for id=1:3 s(id).wa='nko'; s(id).test='5'; s(id).ad(1,1).treasurehunt='asdf' s(id).ad(1,2).treasurehunt='as…
user2305193
  • 2,079
  • 18
  • 39
2
votes
1 answer

How to use find with nested structure in Matlab

I have an array of nested structure. for example st(1).a.b.c=1 st(2).a.b.c=2 st(3).a.b.c=3 ...and so on If I wanted to find the index number of the '.c' objects containing the number 3, I try the following function find([st.a.b.c]==3) It gives…
2
votes
1 answer

Vectorizing structure field access (or modify) matlab? Is it even possible?

After years of anonymity I've just created my account to ask a question which has been bugging me for a while and I just can't seem to find an answer. I really, really tried! Here it goes: If you have the matlab structure array: something(1).toSay =…
2
votes
1 answer

time needed to access struct vs. "loose" variable

I have a question regarding the timing when accessing / reassigning variables either from a matlab struct or a matlab variable (any array): Imagine the scenario that you have one function that creates ten variables (arrays of different dimensions…
S.A.
  • 1,819
  • 1
  • 24
  • 39
2
votes
2 answers

How to query list of variables in Matlab struct matching a certain pattern?

Suppose I have the following struct in Matlab (read from a JSON file): >>fs. fs.dichte fs.hoehe fs.ts2 fs.temperatur fs.ts3 fs.viskositaet fs.ts1 fs.ts4 Each one…
winkmal
  • 622
  • 1
  • 6
  • 16
2
votes
1 answer

Struct name from variable in Matlab

I have created a structure containing a few different fields. The fields contain data from a number of different subjects/participants. At the beginning of the script I prompt the user to enter the "Subject number" like so: prompt='Enter the…
Maheen Siddiqui
  • 539
  • 8
  • 19
2
votes
1 answer

Matlab: is it possible to import data from ascii file and put them in a struct?

I have a file like this (param.txt): JSS 2 ADEV 1 VERS 770 JSD 1 And I want to put the data from this file into a struct with a variable in my workplace. Let say I call it "P", then P is the struct of: Field Value _____ |_______ JSS |2 …
Neros
  • 59
  • 1
  • 5
2
votes
1 answer

Is it possible for a structure field to contain a matrix?

I'm working on an assignment where I have to read a tab delimited text file and my output has to be a matlab structure. The contents of the file look like this (It is a bit messy but you get the picture). The actual file contains 500 genes (the…
embryo3699
  • 55
  • 7
2
votes
1 answer

Initialize array of structs with unknown length fields

Is there value in attempting to pre-allocate an array of structs when the size of the fields is variable? For example: A.x = randn(1,randi(100)); A.y = randn(1,randi(100)); for k = 2:1000 A(k).x = randn(1,randi(100)); A(k).y =…
Mastiff
  • 2,101
  • 2
  • 23
  • 38
2
votes
2 answers

Why is there no need to define fields of structures before assigning them?

I am working with somebody else's code in MATLAB and it looks like he is creating structures, just by using field names without declaring them at all. Is that how it works in MATLAB, you just start using case-insensitive field names of your…
Tyler Durden
  • 11,156
  • 9
  • 64
  • 126
2
votes
1 answer

Create Matlab struct in Python

I have a problem: I want to create a Matlab like struct in Python. The struct I need to create has two fields: "val" and "sl". It has to be a 1x2 struct. The "val" field needs to have two 3x3 matrices inside (e.g A and B), while the "sl" field needs…
Marco Solbiati
  • 123
  • 2
  • 9
1 2
3
9 10