复制
收藏
提问
全网
解释一下 a = [1 2 2 3 3 3 5 5]; result = []; for i = 1:length(a) found = false; for j = 1:size(result, 1) if result(j, 1) == a(i) result(j, 2) = result(j, 2) + 1; found = true; break; end end if ~found result = [result; a(i) 1]; end end result = sortrows(result, 1); disp(result);
刚刚
理解问题解释一下 a = [1 2 2 3 3 3 5 5]; result = []; for i = 1:length(a) found = false; for j = 1:size(result, 1) if result(j, 1) == a(i) result(j, 2) = result(j, 2) + 1; found = true; break; end end if ~found result = [result; a(i) 1]; end end result = sortrows(result, 1); disp(result);
已完成理解「解释一下 a = [1 2 2 3 3 3 5 5]; result = []; for i = 1:length(a) found = false; for j = 1:size(result, 1) if result(j, 1) == a(i) result(j, 2) = result(j, 2) + 1; found = true; break; end end if ~found result = [result; a(i) 1]; end end result = sortrows(result, 1); disp(result);」
展开阅读网页
更专业一些
转笔记
专业
解释一下
a = [1 2 2 3 3 3 5 5];
result = [];
for i = 1:length(a)
found = false;
for j = 1:size(result, 1)
if result(j, 1) == a(i)
result(j, 2) = result(j, 2) + 1;
found = true;
break;
end
end
if ~found
result = [result; a(i) 1]; end
end
result = sortrows(result, 1);
disp(result);不在提醒