필터 지우기
필터 지우기

how to define if or for for the following question

조회 수: 2 (최근 30일)
Abo
Abo 2015년 11월 13일
답변: James Tursa 2015년 11월 13일
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에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by