Effacer les filtres
Effacer les filtres

how to define if or for for the following question

2 vues (au cours des 30 derniers jours)
Abo
Abo le 13 Nov 2015
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

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by