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

2 Ansichten (letzte 30 Tage)
Austin
Austin am 4 Nov. 2013
Bearbeitet: Azzi Abdelmalek am 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);

Antworten (1)

dpb
dpb am 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 :)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by