confront values in 2 matrix
1 次查看(过去 30 天)
显示 更早的评论
hi, i have 2 different matrix with same dimensions and i need to know the min value against 2 values in the same position:
A=[ 0 1 3 5 6]
[2 3 5 8 9]
B=[2 2 4 7 8]
[3 5 7 9 10]
the algorithm confront the zero in first row first column of A with the 2 in first row first column of B and show the min value (0), so for the second row first column of each matrix and so on...i used a for cycle, but i want to know if i can try without any cycle.
In my cicle i use this:
for i 1:size(A)
find(A(1,:)<B(1,:)
end
how can i confront only element by element in the same position without any cycle?
i also have to use the elements of a matrix to do a scalar product using each element in a position and inserting it into a vector:
for i=1:length(A)
for j=1:N (size of rows)
ps1(i,j)=[A(i,j) 0]*[1 0]';
end
end
there is any way to do this without cycles?
i need the value in every position and that value is putted into a vector, then i make the scalar product with [1 0].
Tnx to all for the reply!
采纳的回答
KALYAN ACHARJYA
2019-9-13
编辑:KALYAN ACHARJYA
2019-9-13
"i have 2 different matrix with same dimensions and i need to know the min value against 2 values in the same position:"
A=randi(10,[2,5]) % Random 2x5 A Matrix
B=randi(10,[2,5]) % Random 2x5 B Matrix
result=(A<=B).*A+(A>B).*B
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!