下标索引必须是实数正整数或使用min的逻辑 [英] Subscript indices must either be real positive integers or logicals using min

查看:82
本文介绍了下标索引必须是实数正整数或使用min的逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for control=1:7
    name=strcat('tau: ', num2str(TD(control)),'   PLD: ', num2str(PLD(control)));
    fprintf('Control: %i/7\n', control)
    Maps(control) = struct('GradOFF', [], 'GradON', []);
    for lin=1:size(data(subject).perf_w_off,1)
        fprintf('Lin: %i/64\n', 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

此代码似乎没有错.第一个循环(一个过度控制)运行良好.但是,当再次经历循环(控制= 2)时,执行min1 = min(min(Maps(control).GradOFF))时将出现错误消息.它说:

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.

,但是当我执行mean(mean(Maps(control).GradOFF))时,它正在工作.有人可以告诉我min可能会出什么问题而mean不会出问题吗?

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?

推荐答案

您正在此行中定义变量min:

You are defining a variable min in this line:

min = min([min1, min2]);

完成此操作后,min1 = min(min(Maps(control).GradOFF));将被解释为对变量min的引用,而不是对函数的引用,因此将第二次出现错误.重命名该变量,使其与函数名称不同. max = max([max1, max2]);也是一样,如果您不纠正它,将会遇到同样的问题.

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.

这篇关于下标索引必须是实数正整数或使用min的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆