Use of a specific field of a structure.

10 visualizaciones (últimos 30 días)
Massilon Toniolo da Silva
Massilon Toniolo da Silva el 21 de Mayo de 2017
Editada: dpb el 21 de Mayo de 2017
I want to operate on one of the fields of a struct x in order to calculate standard deviation of it I read that one way to implement it would be to create a new variable and store the appropriate field of the struct x into that new variable. For instance, if you want to operate on the field data of the struct x, define:
y = x.data;
minR = 0.15*std(y); % Standard deviation of y.
In my script x is a ECG signal.
How can I define/express the "appropriate" field of the structure x? What and in which form( how should I write it more concretely)should I replace x and data.
What does "data", in my case, stands for?
And how (in which format more concretely) should x be expressed if I want to place it into y=x.data?
I hope I was clear enough!
I guess I would understand it better by means of an example since my Matlab skills are quite limited. I would to thank for any help and guidance.
Kind regards, Massilon

Respuesta aceptada

dpb
dpb el 21 de Mayo de 2017
"How can I define/express the "appropriate" field of the structure x?"
That all depends on what the fields in structure x are named.
data is the generic name used by importdata for numeric data from text files, for example. load uses the name of the variable in the .mat file. You can create a struct with any legal variable name you desire.
We don't know from your description which of the possible ways you used to get the structure so we don't know what the field name(s) is/are.
fieldnames(x)
will show you.
As for using it, you can create a copy of the data in a new variable, but there is no need to simply to use it; by doing so you use more memory. Simply use the reference to the desired field in the function call is often more succinct and avoids the unnecessary copy--
minR=0.15(std(x.data));
where, of course "data" is the appropriate name you've discovered via fieldnames which may, or may not, actually be 'data'.
  2 comentarios
Massilon Toniolo da Silva
Massilon Toniolo da Silva el 21 de Mayo de 2017
I have entered fieldnames(x) as recommended and could read in the Workspace the following: ans 1x1 cell; maxScale 3; val 2x2500 double; x 1x1 struct.
What would be then the field names? As argument for my function x should be a Nx1 vector of doubles. Can you give me please some further guidance? Thank you very much. Kind regards, Massilon
dpb
dpb el 21 de Mayo de 2017
Editada: dpb el 21 de Mayo de 2017
Paste the actual code and response from the command line instead of trying to paraphrase....details are important.
BUT, looks like two fields;
  1. maxScale (with a value of 3)
  2. val (a 2x2500 numeric array of 2 rows by 2500 columns)
If so, then "data" --> "val" and you'll need to use whichever or the two rows is the one of interest in subscript expression. |What/whom|ever made the data structure should describe the content of the variables inside; one would assume the maxScale is some sort of normalization (is/was/should be?) applied to the values.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by