在矩阵中表示特定值的数量

时间:2016-10-25 19:36:24

标签: matlab matrix

我使用下面的代码来测试是否满足某些条件然后我想计算每个条件满足的次数,这样我就可以做进一步的计算。

for x = 1:35

    N = csvread(fullpath1, 1);  

    Resultgenerated = N(x,1);
    Resultgiven= N(x,2);

    outcome1 = [];
    outcome2 = [];

    if (Resultgenerated >= 1) && (Resultgiven  >= 1)
        outcome1 = 1; %true positive
    elseif (Resultgenerated <= 0) && (Resultgiven >= 1)
    outcome1 = 2; %'False Positive';
    end
    if (Resultgenerated <= 0) && (Resultgiven <= 0)
        outcome1 = 3; %'True Negative';
    elseif (Resultgenerated >= 1) && (Resultgiven <= 0)
        outcome1 = 4; %'False Negative';
    end

    hout{x} = outcome1;
end 
sum(hout(:) == 4)

我收到了错误

Undefined operator '==' for input arguments of type 'cell'.

Error in potential_compare (line 132)
sum(hout(:) == 4)

如果有人有任何建议会很棒!

感谢

1 个答案:

答案 0 :(得分:1)

如果您不需要,请不要使用细胞。对于您的情况,您只存储结果outcome1

hout = zeros(1,35);
for x = 1:35
% bunch of stuff
hout(x) = outcome1;
end
sum(hout == 4)