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

Order fields in struct

I would like to push a field before another one in a struct. I coulnd't find any functions with Matlab help. Is there an easy and efficient way to implement this? Do I have to shift all the struct fields when I insert a new one 'before an other…
user2305193
  • 2,079
  • 18
  • 39
1
vote
1 answer

matlab vertically concatenate logical indexed arrays

I Have a 8x18 structure with each cel containing a column vector of occurrences of a single event. I want to obtain data from some of these fields concatenated in a single array, without having to loop through it. I can't seem to find a way to…
Jasper
  • 75
  • 5
1
vote
1 answer

How can I change the data type of a field in a structure array?

I have a 2417-by-50 structure array in MATLAB and am trying to find a vectorized way to convert some of the field types: I have a column of characters that I want to convert into a string type: [DataS.Sector] = string([DataS.Sector]); but its not…
1
vote
1 answer

Creating a Struct Array From Excel Sheet

I have written a matlab function that accepts the string (name) of an excel document as input: function printOut = modData(inputExcel) [num,txt,raw]=xlsread(inputExcel) The excel sheet has the following data: First-Name | Last-Name | Subject1 |…
JOG-Design
  • 207
  • 2
  • 5
  • 14
1
vote
1 answer

fast access of an element in struct array based on multple criteria

I asked this question last time. Answers there were very helpful. I want to suggest a slight variant. I need to access that element of a struct array which has a(i).x==5.65 && a(i).y==32.23? Again i can run the good old for loop and find the index…
user_1_1_1
  • 903
  • 1
  • 12
  • 27
1
vote
1 answer

Save variables into a struct from the workspace

As you can see in the picture, I have three variables, two are named number_of_steps_... and the third one is struct. How can I save the content saved in the number_of_steps variables into struct? I have tried the save command but that doesn't…
john.steak
  • 59
  • 9
1
vote
1 answer

Force conversion of struct to object in MATLAB loadobj function

I am working with a custom defined class I called "PathObj_Standard". I want to make sure that when I load this class, if the property CalcDate was saved as a cell array it is converted to a standard array. However, I changed the class definition…
LudoZ
  • 11
  • 1
1
vote
1 answer

Update Values of a field in structure | Matlab

I have a structure (sa1) with fields : FirstImpression, FashionSense, Compatibility (7*1) size I want to find the indexes of maximum value of FirstImpression & Fashion Sense and increment the value of Compatibility by 1 on the same index. I have…
aman saraf
  • 45
  • 9
1
vote
3 answers

Matlab sum struct array rows based on criteria

I have a struct array in Matlab as follows: temp_links = struct('src',{},'dest',{}, 'type', {}, 'datarate', {}); the data in temp_links is as follows: =============================== src dest type …
smyslov
  • 1,279
  • 1
  • 8
  • 29
1
vote
1 answer

How can I vectorize access to substructures in Matlab?

I'll jump to the question first, then some supporting information: Suppose I have the following: motor(1).Voltage = 96.2; motor(2).Voltage = 48.0; processingStation(1).FeedstockMotor.Voltage = 96.2; processingStation(2).FeedstockMotor.Voltage =…
Chuck
  • 1,977
  • 1
  • 17
  • 23
1
vote
2 answers

Having trouble publishing a matlab function

I have a .m script file which contains 95% of my work. Part of my assignment was to write a function that performs a certain calculation and then utilize the function for various examples. I created a separate .m file for the function and named it…
Daven.Geno
  • 21
  • 4
1
vote
1 answer

Iterating structures array field's values

How to iterate/loop structures array field's values. For 1x1 struct student = struct(); student.name = 'jim'; student.gpa = 1.9; I do this : fields = fieldnames(student) for i=1:numel(fields) var = fields(i) end But I don't how to iterate 1 x…
1
vote
3 answers

Convert struct to matrix MATLAB

Is there a way to convert a struct (2 fields with 52 variables each) to a matrix (2x52)? Thank you struct: sym (1x53) prob (1x53) I have tried the following which gives me a 1 x 1 cell array symProb = reshape({x.sym}, size(53)); I have…
Jespar
  • 1,017
  • 5
  • 16
  • 29
1
vote
1 answer

Extracting a vector from a struct

I got a struct after using dir(directoryName). I want to get a vector containing all the file names in that folder. How do I extract a vector of names from the struct? Is there a better way to get a vector with the names of all files in a…
havakok
  • 1,185
  • 2
  • 13
  • 45
1
vote
3 answers

How to access and store selected fields from a dynamic structure in matlab?

I have a huge dynamic structure. It looks something like this: s.one.name = 'Mr. Doe'; s.one.time = '12:00'; s.one.ID = '209'; s.one.data = 'Data1'; s.two.name = 'Ms. Jane'; s.two.time = '13:00'; s.two.ID = '210'; s.two.data =…
Nick
  • 55
  • 8