d*******2 发帖数: 340 | 1 比如4x3的矩阵,现有一向量a=[0 0 0]; 如何找到他的行号是第四行?先谢了!
0 0 20
0 5 10
4 9 4
0 0 0 |
r****x 发帖数: 3613 | 2 row = find(a==[c c c])
【在 d*******2 的大作中提到】 : 比如4x3的矩阵,现有一向量a=[0 0 0]; 如何找到他的行号是第四行?先谢了! : 0 0 20 : 0 5 10 : 4 9 4 : 0 0 0
|
d*******2 发帖数: 340 | 3 >> a=[0 0 20; 0 5 10; 4 9 4; 0 0 0];
a =
0 0 20
0 5 10
4 9 4
0 0 0
>> row = find(a==[0 0 0])
??? Error using ==> eq
Matrix dimensions must agree.
【在 r****x 的大作中提到】 : row = find(a==[c c c])
|
r****x 发帖数: 3613 | 4 sorry, i tried the new one.
[row,col]=find(a==[0]);
for i=1:4
if a(i,1)==a(i,2) && a(i,1)==a(i,3) && a(i,1)==0
i
end
end
i =
4
【在 d*******2 的大作中提到】 : >> a=[0 0 20; 0 5 10; 4 9 4; 0 0 0]; : a = : 0 0 20 : 0 5 10 : 4 9 4 : 0 0 0 : >> row = find(a==[0 0 0]) : ??? Error using ==> eq : Matrix dimensions must agree.
|
r****x 发帖数: 3613 | 5 i can't find any simple pre designed matlab functions.
【在 r****x 的大作中提到】 : sorry, i tried the new one. : [row,col]=find(a==[0]); : for i=1:4 : if a(i,1)==a(i,2) && a(i,1)==a(i,3) && a(i,1)==0 : i : end : end : i = : 4
|
t***s 发帖数: 4666 | 6 find(ismember(A,a,'rows'))
【在 d*******2 的大作中提到】 : 比如4x3的矩阵,现有一向量a=[0 0 0]; 如何找到他的行号是第四行?先谢了! : 0 0 20 : 0 5 10 : 4 9 4 : 0 0 0
|
d*******2 发帖数: 340 | 7 Thank you very much and admire you very much!
【在 t***s 的大作中提到】 : find(ismember(A,a,'rows'))
|
j****x 发帖数: 943 | 8 Just curious, isn't "find" pretty slow? any other alternatives? Only for
matlab or using python? |
i******t 发帖数: 370 | 9 This code is more efficient though harder to read:
e = A-repmat(a, [size(A, 1), 1]);
i = find(sum(e==0, 2)==size(A, 2));
"find" only operates on a vector so it's fast.
【在 j****x 的大作中提到】 : Just curious, isn't "find" pretty slow? any other alternatives? Only for : matlab or using python?
|
b****r 发帖数: 5889 | 10 那这样会快点吗
find(ismember(A',a','column'))
【在 i******t 的大作中提到】 : This code is more efficient though harder to read: : e = A-repmat(a, [size(A, 1), 1]); : i = find(sum(e==0, 2)==size(A, 2)); : "find" only operates on a vector so it's fast.
|
|
|
t***s 发帖数: 4666 | 11 find(ismember()) operates on a vector too. hehe.
i don't know how ismember is implemented.
【在 i******t 的大作中提到】 : This code is more efficient though harder to read: : e = A-repmat(a, [size(A, 1), 1]); : i = find(sum(e==0, 2)==size(A, 2)); : "find" only operates on a vector so it's fast.
|
c****w 发帖数: 565 | 12 naive to argue about function speed under MATLAB, if you want speed, forget
about MATLAB |
g****y 发帖数: 199 | 13 even for Matlab, high speed is always better, and those discussions are also
helpful. don't be too picky:)
forget
【在 c****w 的大作中提到】 : naive to argue about function speed under MATLAB, if you want speed, forget : about MATLAB
|
i******t 发帖数: 370 | 14 The speed matters.
If you have a matlab code written in 3 recursive loops with 100 iterations
each, you will need to optimize the code...
forget
【在 c****w 的大作中提到】 : naive to argue about function speed under MATLAB, if you want speed, forget : about MATLAB
|
d*******2 发帖数: 340 | 15 I guess 99% of people who complain matlab's speed are not using matlab
properly, although you might be the rest 1%.
forget
【在 c****w 的大作中提到】 : naive to argue about function speed under MATLAB, if you want speed, forget : about MATLAB
|
p*****o 发帖数: 40 | 16 er...
【在 d*******2 的大作中提到】 : I guess 99% of people who complain matlab's speed are not using matlab : properly, although you might be the rest 1%. : : forget
|