Azzera filtri
Azzera filtri

Map an array yo another one

10 visualizzazioni (ultimi 30 giorni)
evangeline
evangeline il 15 Feb 2018
Modificato: Stephen23 il 15 Feb 2018
I have an array like: A=[3,5,6,10] and I need to map it to another one like: B=[1,2,3,4] so instead of returning A, I can return B. how can I do this?
  2 Commenti
Guillaume
Guillaume il 15 Feb 2018
The question is really not clear. What does map mean? How do you go from [3 5 6 10] to [1 2 3 4]? What is the rule?
KL
KL il 15 Feb 2018
B=A ?

Accedi per commentare.

Risposte (2)

Andrei Bobrov
Andrei Bobrov il 15 Feb 2018
Modificato: Andrei Bobrov il 15 Feb 2018
A=[3,5,6,10];
B=[1,2,3,4];
C = randsrc(8,5,B);
ii = discretize(C,B);
out = A(ii);

Stephen23
Stephen23 il 15 Feb 2018
Modificato: Stephen23 il 15 Feb 2018
Use interp1:
>> A = [3,5,6,10];
>> B = [1,2,3,4];
>> interp1(A,B,[5,10])
ans =
2 4

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by