Associate numeric values to object arrays

1 view (last 30 days)
I have a table with a list of numerical sequences. Here you can see how each object looks like:
>>x
x=
0 1 2 0 1 2
1 2 0 1 2 0
>> class(x)
ans =
'double'
>> A(1,1:3000)
ans =
Columns 1 through 16
0.3616 0.3090 0.2184 0.1905 0.2085 0.1760 0.1237 0.0691 0.0802 0.0427 -0.0064 -0.0402 -0.0670 -0.0386 0.0134 0.0204
Columns 17 through 30
0.0356 0.0732 0.1071 0.1062 0.0400 0.0064 -0.0789 -0.1627 -0.1519 -0.0841 -0.0818 -0.1089 -0.1376 -0.0800
I want to convert each number to an object previously created. For instance, A, B and C are class double (vectors of 1*3000). Therefore we want to associate an convert 0 to A, 1 to B and 2 to C. To sum up, convert the numerical sequence to a sequence of objects.

Accepted Answer

Matt J
Matt J on 8 Jun 2019
Edited: Matt J on 8 Jun 2019
I think this is what you mean?
objectList={A,B,C};
result=objectList(x+1)
  1 Comment
Matt J
Matt J on 8 Jun 2019
Fina's comment moved here:
Absolutely! Thank you, I'm new to Matlab!

Sign in to comment.

More Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!