Pattern search and string indexing
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ronald
am 4 Jun. 2020
Kommentiert: Ameer Hamza
am 5 Jun. 2020
I have two cell arrays:
A = {[x(2)& x(4)& x(1)],[x(3),x(5)],[x(2),x(1)]}
B = {2465,2514,147,236,58}
where the integers in A are the indices of B items. I want to replace those indices with actual values as:
C = {[2514,236,2465],[147,58],[2514,2465]}
For loop is a bit slow. Is there an alternative?
1 Kommentar
Akzeptierte Antwort
Ameer Hamza
am 4 Jun. 2020
Something like this
A = {[2 4 1],[3 5],[2 1]}; % you can put indexes as numbers
B = {2465,2514,147,236,58};
A_new = cellfun(@(x) {[B{x}]}, A)
3 Kommentare
Weitere Antworten (1)
madhan ravi
am 4 Jun. 2020
A = @(x){[x(2), x(4), x(1)],[x(3),x(5)],[x(2),x(1)]}
B = {2465,2514,147,236,58}
C = A(B)
Siehe auch
Kategorien
Mehr zu Characters and Strings 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!