- a non-scalar structure
- a cell array.
Create cell with vector from looping trough struct
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello. I have a struct, 1x30, each field has a 1*X columns with index values. some fields are also empty. Im trying to greate a vector, which goes from each index value + 100index points. Then save this as a cell containing a vector ranging from indexvalue to indexvalue +100. for all columns within the 30 fields. Looking at the picture below, indexstruct.col_5, i need a vector going from
149111, 149112,149113....149211
385351, 385352, 385353,.....385451
and so on for all 168 columns in indexstruct.col_5 but also for all columns in col_1 to col_30.
The vectors are then to be used to findi maxvalue within each index-range, ranging from start to 100 indexpoints later. indexvalues correspond to time in an acceleration time history.
Gratefull for any help i can get!
For what its worth im posting my code below. Although I belive its pretty far from achiving what i want.
vec2={}
fn = fieldnames(indexstruct);
for k=1:numel(fn) %looping through struct
for i = length(indexstruct.(fn{k}))
vec2 = (indexstruct.(fn{k})(:,i)):indexstruct.(fn{k})(:,i)+100;
vec2= {vec2;vec2(k)};
end
end

2 Kommentare
Stephen23
am 16 Mai 2020
Using numbered fields makes accessing your data more complex than it needs to be. Much simpler:
Both of these would make accessing your data easier.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!