一些矩阵运算和提取数据
我想问一个关于MATLAB中矩阵运算的问题。
假设我们有这个矩阵:
A = [1 1 17
1 1 14
1 2 10
1 2 11
2 1 9
2 1 9
2 2 13
2 2 12
3 1 18
3 1 15]
我想要第一列(比如 M)和第二列(比如 D)来控制整个矩阵,根据以下条件生成一行矩阵:
程序将要求用户输入 M 的值那么D如下:
M = input(' ENTER M VALUE = ') ;
D = input(' ENTER D VALUE = ') ;
现在,输出将是M和D对应的2个值,这两个值将从第三列中取出,
例如:
if M = 1 and D = 2 , the output is B = 10 ; 11
另一个例子:
if M = 3 and D = 1 , the output is B = 18 ; 15
等等。
实际上,我知道如何使用 if 语句解决这个问题,但是我有大量数据,这将需要很长时间。我确信有一个捷径可以做到这一点。
谢谢。
I want to ask a question in some matrix operations in MATLAB.
Assume we have this matrix:
A = [1 1 17
1 1 14
1 2 10
1 2 11
2 1 9
2 1 9
2 2 13
2 2 12
3 1 18
3 1 15]
I want the first column, say M and the second column, say D to control the entire matrix to result to one row matrix depending on the following condition:
the program will ask the user to enter the values of M then D as follows:
M = input(' ENTER M VALUE = ') ;
D = input(' ENTER D VALUE = ') ;
Now, the output will be the corresponding 2 values to M and D, and these two values will be taken from the third column,
for example:
if M = 1 and D = 2 , the output is B = 10 ; 11
another example:
if M = 3 and D = 1 , the output is B = 18 ; 15
and so on.
Actually, I know how to solve this using if statement but I have large data and this will take very long time. I am sure that there is a short way to do that.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是
The short way to do it is