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

1 次查看(过去 30 天)
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);

回答(1 个)

dpb
dpb 2013-11-4
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 :)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by