Convert structure to a vector?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear all, I need a help with accessing and converting a structure
if true
G = {'A', 'B'};
A = 1;
B = 2;
end
how can I convert it to a vector C = [1,2]
Thank you,
2 Commenti
Risposte (1)
Stephen23
il 25 Lug 2018
>> G = {'A','B'};
>> V = [1,2]; % or [A,B]
>> [~,idx] = ismember(G,{'A','B'});
>> V(idx)
ans =
1 2
Or using char vectors (simpler):
>> G = 'AB';
>> V = [1,2];
>> [~,idx] = ismember(G,'AB');
>> V(idx)
ans =
1 2
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!