min function on two arrays
40 次查看(过去 30 天)
显示 更早的评论
I've read the documentation on the min function, but still don't understand how it works on two arrays. I have the following:
dS=zeros(1,N)
dS=min(cA(i+1,:),cB(i+1,:))
where cA and cB are equally sized arrays. Doesn't the min function just take the value at equivalent locations in cA or cB that is the lowest. So if position 10,50 in cA is 5 and the same position in cB is 3, min returns 3 in the resulting row vector, dS, at column 50. Is that correct?
3 个评论
James Tursa
2021-6-8
编辑:James Tursa
2021-6-8
This line creates dS as a vector:
dS=zeros(1,N)
Then this line completely overwrites the dS you just created and instead assigns dS the result of the min( ) function call:
dS=min(cA(i+1,:),cB(i+1,:))
I.e., the first line is completely useless and accomplishes nothing because it gets overwritten in the second line.
And yes, cA(i:1,:) and cB(i+1,:) will be a row vectors if i is a scalar.
采纳的回答
SALAH ALRABEEI
2021-6-8
%
dS=min([cA(i+1,:),cB(i+1,:)])
3 个评论
SALAH ALRABEEI
2021-6-8
Oops, yes it must be semicol; Thanks.
% correction
dS=min([cA(i+1,:);cB(i+1,:)])
Walter Roberson
2021-6-8
That would work in the case that cA and cB have the same number of columns.
The original code
dS=min(cA(i+1,:),cB(i+1,:))
would also work if one of cA or cB had a single column and the other one did not.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!