How to make group of ones more systematic approach?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Zeynab Mousavikhamene
le 21 Fév 2020
Réponse apportée : Walter Roberson
le 22 Fév 2020
I have this groups of ones:
group = [ ones(size(Ribboned_100.unpatterned_B1.(string(var(i))))); 2 * ones(size(Ribboned_100.unpatterned_B10.(string(var(i))))); ...
3 * ones(size(Ribboned_100.unpatterned_He.(string(var(i))))); 4 * ones(size(Ribboned_100.unpatterned_MD.(string(var(i)))));...
5 * ones(size(Ribboned_100.unpatterned_HT.(string(var(i))))); 6 * ones(size(Ribboned_100.unpatterned_BT.(string(var(i)))));
7 * ones(size(Ribboned_100.unpatterned_NI.(string(var(i)))))]
and I have this set of strings here:
XT= {'B1','B10','He','MD','HT','BT','NI'};
I think the way I make "group" above is not efficient and there should be a way to make the "group" systematically using "XT".
Any suggestion?
1 commentaire
Spencer Chen
le 21 Fév 2020
You can loop or use arrayfun to make it more systematic, but not sure if it will be more efficient. This involves assigning each set of ones to a cell then use cat() to concatenate them.
That's my limit of Matlab without know more about your data structure.
Blessings,
Spencer
Réponse acceptée
Walter Roberson
le 22 Fév 2020
Before the loop, struct2cell(Ribboned_100) . Then look at the fieldnames() of Ribboned_100, and match those against the names from XT, getting the respective indices. Extract those cells from the cell array.
Now you can loop over i, extracting the fields named by var{i} from those particular cells.
All of this is only likely to be more efficient than what you have if the maximum index is large.
If the var{i} between them cover all of the fields, then you could reorderfields() of those cell arrays according to var order, and then cell2mat(), after which you would be doing numeric indexing instead of struct reference.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!