sara
sara

Reputation: 3

use structure in matlab

I want to use structure in matlab but in first iteration it's run correctly and in other iteration give that message .

1x2 struct array with fields:

my code is :

    for i=1:lenfd
    currow=rees(i,:)
    maxcn=max(currow)
       if maxcn~=0
         maxin=find(currow==maxcn)
         ress(i).x =maxin
       end
    end

thank you.

Upvotes: 0

Views: 64

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38042

That message is not a warning or error. That's just MATLAB printing the output of an operation. And it does that by default, unless you suppress it by appending a semicolon to the command:

for ii = 1:lenfd

    currow = rees(ii,:);   % <=== NOTE: semicolons at the end
    maxcn  = max(currow); 

    if maxcn ~= 0
        ress(ii).x = find(currow==maxcn);
    end

end

Note that max() may have 2 outputs, the second output being the first index into the array where the maximum occurred. If you know beforehand that any maximum will occur only once, you can skip the call to find() and use the second output of max().

Upvotes: 3

Related Questions