MATLAB--巧妙运⽤逻辑数组测试数据:
>> yv = magic(4)
yv =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 1
5 1
matlab数组赋值>> y = [3;4;2;1]
y =
3
4
2
1
style 1
yv=[1:num_labels] == y
>> yv = [1:4] == y
yv =
4×4 logical 数组
0 0 1 0
0 0 0 1
0 1 0 0
1 0 0 0
style 2
yv = zeros(m, num_labels);
for i = 1:m
yv(i, y(i)) = 1;
end
>> yv = zeros(4,4)
yv =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> for i = 1:4
yv(i, y(i)) = 1;
end
>> yv
yv =
0 0 1 0
0 0 0 1
0 1 0 0
1 0 0 0
style 3
all_combos = eye(num_labels);
y_matrix = all_combos(y,:) >> all_combos = eye(4);
>> y_matrix = all_combos(y,:)
y_matrix =
0 0 1 0
0 0 0 1
0 1 0 0
1 0 0 0
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论