Azzera filtri
Azzera filtri

matrix input if mat(1) is > than mat(2)

3 visualizzazioni (ultimi 30 giorni)
Austin
Austin il 4 Nov 2013
im trying to find if an mat(1)is > mat(2) and so on.
below is my attempt:
function [specialmax] = specialmax(x)
[r c]=size(x)
t=x(1,:);
for i=2:r
for j=1:c
specialmax=x(1,j);

Risposte (1)

dpb
dpb il 4 Nov 2013
function [specialmax] = specialmax(x)
[r c]=size(x)
t=x(1,:);
for i=2:r
for j=1:c
specialmax=x(1,j);
...
Need to set the initial condition outside the loop; you're overwriting specialmax each time with the first row value as it is.
function [specialmax] = specialmax(x)
[r c]=size(x);
specialmax=(1,:); % initialize to first row
for i=2:r
for j=1:c
...now updated if needs be, but do it in the output array...
Good try...just a tiny logic boo-boo :)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by