Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Austin
Austin el 4 de Nov. de 2013
Editada: Azzi Abdelmalek el 4 de Nov. de 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);

Respuestas (1)

dpb
dpb el 4 de Nov. de 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 :)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by