MATLAB Answers

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

2 ビュー (過去 30 日間)
anil hamzacebi
anil hamzacebi 2019 年 10 月 17 日
コメント済み: Steven Lord 2019 年 10 月 18 日
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.
i tried something but could not find a way so i am asking here. Please help.

  0 件のコメント

サインインしてコメントする。

採用された回答

Kevin Phung
Kevin Phung 2019 年 10 月 17 日
編集済み: Kevin Phung 2019 年 10 月 17 日
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

  0 件のコメント

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2019 年 10 月 17 日
編集済み: Steven Lord 2019 年 10 月 17 日
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
head(results)
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);
head(resultsCategorical)
The IncludedEdge name-value pair argument may also be useful depending on whether you want 25 to be first or second gear etc.

  2 件のコメント

anil hamzacebi
anil hamzacebi 2019 年 10 月 17 日
Thank you for your great answer!!!
I've tried your code and it's working well. i was not expecting two excellent help these quickly!!
i couldn't mark your respond i guess because that's one shot but i'm writing this comment also going to flag your respond as a solution i think it will help other people
Thank you again and wish you succes!!
Steven Lord
Steven Lord 2019 年 10 月 18 日
Flags are intended to report spam or other problems. [Think of the idea of a red flag.] If you want to indicate to people that this answer helped you even though it isn't the accepted answer, you can leave a comment to that effect (like you did) and/or vote for the answer.
Since this is my answer that got flagged, I'll leave it for someone else to remove the flag.

サインインしてコメントする。

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by