indexing a field in a structure

1 Ansicht (letzte 30 Tage)
matthias daeumer
matthias daeumer am 9 Okt. 2020
Bearbeitet: Stephen23 am 9 Okt. 2020
I need to save every mean from this structure into a vector. (there are 270 fields)
m_vector(1:270) = s(11).structure.mean(1:270) does not work and I am not sure why
  2 Kommentare
matthias daeumer
matthias daeumer am 9 Okt. 2020
This is the error:
>> m_vector(1:270) = s(vv).structure.Mean(1:270)
Expected one output from a curly brace or dot indexing expression, but there were 270 results.
Stephen23
Stephen23 am 9 Okt. 2020
Bearbeitet: Stephen23 am 9 Okt. 2020
"I need to save every mean from this structure into a vector. (there are 270 fields)"
I very much doubt that there are 270 fields. Most likely you are confusing the number of fields (displayed as headers in the Variable Viewer) with the number of elements in the structure (displayed as rows). In fact these are totally independent things.
But until you actually upload the data in a mat file by clicking on the paperclip button, we will have to rely on guessing.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 9 Okt. 2020
Bearbeitet: Stephen23 am 9 Okt. 2020
Your indexing is not correct. If s(11).structure has exactly 270 elements, then all you need is this:
out = [s(11).structure.Mean]
Read more on how to use comma-separated lists:
For an explanation of why your indexing is not correct:

Weitere Antworten (1)

Ameer Hamza
Ameer Hamza am 9 Okt. 2020
Bearbeitet: Ameer Hamza am 9 Okt. 2020
Try this
all_means = cell2mat(arrayfun(@(i) {[s(i).structure.mean]}, 1:numel(s)))
% or
all_means = cell2mat(arrayfun(@(s_) {[s_.structure.mean]}, s))

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by