## How can i create a new matrix that equationally depends on another matrix?

### anil hamzacebi (view profile)

on 17 Oct 2019
Latest activity Commented on by Steven Lord

on 18 Oct 2019

### Kevin Phung (view profile)

i have a 1:1180 matrix that gives me variable velocity values and i need to create a new 1:1180 matrix to get transmission ratios for each velocity value.

R2017b

### Kevin Phung (view profile)

on 17 Oct 2019
Edited by Kevin Phung

### Kevin Phung (view profile)

on 17 Oct 2019

Here's a potential solution:
gear = zeros(1,numel(v)); % initialize gear array
gear(and(v>=0,v<25)) = 1; %logical indexing
gear(and(v>=25,v<50)) = 2;
gear(and(v>=50,v<70)) = 3;
gear(and(v>=70,v<90)) = 4;
gear(v>=90) = 5;)
Note: you should double check my inequalities. Im not sure where you want the bounds to be inclusive.
for example: v>=70 and v<90, versus v>=70 and v<=90
Let me know if this is what you needed

### Steven Lord (view profile)

on 17 Oct 2019
Edited by Steven Lord

### Steven Lord (view profile)

on 17 Oct 2019

I would use discretize.
% Generate some sample data for this example
v = randi([0, 100], 50, 1);
% Discretize into bins (the second input) with values given by the third input
% The right edge of the last bin should be at least as large as
% the largest element in v
gear = discretize(v, [0; 25; 50; 70; 90; 100], (1:5).');
% Put the sample data and discretized data into a table for easy display
results = table(v, gear);
% Show the first several rows of the results table
Depending on whether I was planning to use the gear information for later computation or for reporting to the user, I might create categorical data instead of numeric.
gearCategories = discretize(v, [0; 25; 50; 70; 90; 100], ...
'categorical', ["first"; "second"; "third"; "fourth"; "fifth"]);
resultsCategorical = table(v, gearCategories);
The IncludedEdge name-value pair argument may also be useful depending on whether you want 25 to be first or second gear etc.

anil hamzacebi

on 17 Oct 2019