Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
954 views
in Technique[技术] by (71.8m points)

matlab - Subscript indices must either be real positive integers or logicals using min

for control=1:7
    name=strcat('tau: ', num2str(TD(control)),'   PLD: ', num2str(PLD(control)));
    fprintf('Control: %i/7
', control)
    Maps(control) = struct('GradOFF', [], 'GradON', []);
    for lin=1:size(data(subject).perf_w_off,1)
        fprintf('Lin: %i/64
', lin);
        for col=1:size(data(subject).perf_w_off,2)
            [x1, fval, exitflag, output] = fminunc(...)
            Maps(control).GradOFF(lin,col) = abs(x1(2));
            [x2, fval, exitflag, output] = fminunc(...)
            Maps(control).GradON(lin,col) = abs(x2(2));
        end
    end

    min1 = min(min(Maps(control).GradOFF));
    min2 = min(min(Maps(control).GradON));
    min = min([min1, min2]);
    max1 = max(max(Maps(control).GradOFF));
    max2 = max(max(Maps(control).GradON));
    max = max([max1, max2]);

    figure(map1);

    subplot(2,7,control)
    image1 = mat2gray(Maps(control).GradOFF,[min, max]);
    imshow(image1,[]);
    title(strcat(name, ' Grad Off'))

    subplot(2,7, control+7)
    image2 = mat2gray(Maps(control).GradON,[min, max]);
    imshow(image2,[]);
    title(strcat(name, ' Grad On'))
end

Nothing seems to go wrong with this code. The first loop (the one over control) is doing fine. However when going through the loop again (control = 2), then an error message appears when doing min1 = min(min(Maps(control).GradOFF)). It says:

Subscript indices must either be real positive integers or logicals.

but when I'm doing mean(mean(Maps(control).GradOFF)) it is working. Could someone tell me what could go possibly wrong with min that won't with mean?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

You are defining a variable min in this line:

min = min([min1, min2]);

Once you have done that, min1 = min(min(Maps(control).GradOFF)); is being interpreted as a reference to the variable min, not the function, hence the error on the second time around. Rename that variable so it's not got the same name as the function. The same goes for max = max([max1, max2]); which will give you the same problem if you don't correct it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...