how to define if or for for the following question

2 次查看(过去 30 天)
I have matrix x=[1 2 4 5] and matrix y= [3 4 2 4], i wanna find if x(i,j)-y(i,j)<0 put highest value between that (i,j) in a new matrix, and if x(i,j)-y(i,j)>0 put the lowest value between that (i,j) in a new matrix, how can i do that? for example here: x-y= [-2 -2 2 1] because the first row and column of x-y in less than zero (-2), as a result in new matrix (like d) the first row and column must be the highest value between x(1,1) and y(1,1) and so on...,matrix d here would be d=[3 4 2 4]. hope to make sense

采纳的回答

James Tursa
James Tursa 2015-11-13
xy = [x;y];
minxy = min(xy);
maxxy = max(xy);
g = x - y < 0;
d = x;
d(g) = maxxy(g);
d(~g) = minxy(~g);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by