I have a large matrix which has RPM in the first column and Torques populating the rest of the matrix. I need help finding a way to search the first column for a set rpm and then search that row for value of torque, from that i need the position of that value in the matrix to then find an efficiency value in an identical sized matrix.
I have so far:
RPM_val =1000; [row] = find(T_T==RPM_val)
This gives me the row where the 1000rpm is, how do i then search just that row for the value of torque i am after,or the nearest value to it.
Thank you

 采纳的回答

John D'Errico
John D'Errico 2018-2-7
编辑:John D'Errico 2018-2-7
Time to learn about matrix indexing?
[row] = find(T_T==RPM_val)
First of all, this searches the ENTIRE matrix for a value equal to RPM_val. If it turns out that another column happens to hit that value, you will get the wrong answer. While that might be a spectacularly unlikely event, or so you think, something as silly as this is the source of many a bug. Good code avoids obvious bugs by careful planning.
So instead, do this:
[row] = find(T_T(:,1)==RPM_val);
That searches only the first column. Be careful though. What is there is no exact match? find will return empty then. Do you want to find the closest?
Once you do have the row, then consider what this does:
T_T(row,2:end)
That extracts a vector of elements only in the indicated row, excluding the first column. How might you use that in a secondary search using find?

5 个评论

It is indeed time to learn about them! thank you.
Ok that makes more sense with searching the first column, however you are correct, the RPM is listed in ascending order in increments of 50, the data that will feed into this could be any iteration of RPM so that would be the next problem, rounding to the nearest 50 etc.
Once i have the row i would need to then search that again for the nearest value of input torque.
This is only my 2nd time using Matlab and not knowing the terminology when searching for help is a great hindrance so thank you for taking the time to explain some
Currently trying:
Torques=T_T(row,2:end);
[C Torque_col] = min(abs(Torques-Torque_val))
which gives me the first value nearest to the torque demand, which for this purpose might be ok but its not exactly accurate etc.
If all you have are a list of values, and you want to find the nearest, then that seems quite reasonable.
You can always go into more depth. But more complexity often brings problems that you will need to solve. If they are a well behaved monotonic sequence, and you wanted to use interpolation to find an intermediate value, then interp1 could help you. Even more complexity (and SOMETIMES more accuracy) would come from a spline interpolant of some sort. But you need to decide how much you want to invest into a problem.
It will work to the closest and in this instance i think it should be fine, the gaps efficiency it finally relates to are very small so for now i think this will work.
As for the interpolation, if i interp the rpm values i think it will quickly start going above my head, for now i will keep pushing forward with what you have shown me and see how far i get. Thank you again for the help!, it is greatly appreciated
Exactly. Don't invest more time or effort in something that does not need it. Programming time is important. If the gain is small, invest your mental energy where you will realize a useful gain.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by