How to access randomly selected index in nested structures
Ältere Kommentare anzeigen
I want to access intexes that are into a structure that are nested within another structure. I have this code working through every ith element, and I want to add to the code randomly selected values j. In my case j is from 1 to 365 day of the year.
for i=1:n
fileName=structName(i).nestedStructName(j).name
end
Any ideas?
Darina
Akzeptierte Antwort
Weitere Antworten (2)
Mischa Kim
am 28 Jan. 2014
How about
fileName=structName(i).nestedStructName(randi(365,1)).name
Is this what you are looking for?
7 Kommentare
Darina
am 28 Jan. 2014
Mischa Kim
am 28 Jan. 2014
Does nestedStructName have 365 elements?
Darina
am 28 Jan. 2014
Darina
am 28 Jan. 2014
Mischa Kim
am 28 Jan. 2014
Just before entering the for-loop add:
[rS, cS] = size(structName)
[rnS, cnS] = size(structName(rS).nestedStructName)
What do you get?
Darina
am 28 Jan. 2014
Darina
am 28 Jan. 2014
Shivaputra Narke
am 28 Jan. 2014
0 Stimmen
May this works,
for i=1:n j=1+round(364*rand(1)); fileName=structName(i).nestedStructName(j).name end
1 Kommentar
Darina
am 28 Jan. 2014
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!