octave - ex3 coursera机器学习中的displaydata函数
问题描述
我面临一个问题,这是我的脚本。一些结尾或括号问题,但我已经检查过注意事项丢失。
function [h, display_array] = displayData(X, example_width)
%DISPLAYDATA Display 2D data in a nice grid
% [h, display_array] = DISPLAYDATA(X, example_width) displays 2D data
% stored in X in a nice grid. It returns the figure handle h and the
% displayed array if requested.
% Set example_width automatically if not passed in
if ~exist('example_width', 'var') || isempty(example_width)
example_width = round(sqrt(size(X, 2)));
end
% Gray Image
colormap(gray);
% Compute rows, cols
[m n] = size(X);
example_height = (n / example_width);
% Compute number of items to display
display_rows = floor(sqrt(m));
display_cols = ceil(m / display_rows);
% Between images padding
pad = 1;
% Setup blank display
display_array = - ones(pad + display_rows * (example_height + pad), ...
pad + display_cols * (example_width + pad));
% Copy each example into a patch on the display array
curr_ex = 1;
for j = 1:display_rows
for i = 1:display_cols
if curr_ex > m,
break;
end
% Copy the patch
% Get the max value of the patch
max_val = max(abs(X(curr_ex, :)));
display_array(pad + (j - 1) * (example_height + pad) +
(1:example_height), ...
pad + (i - 1) * (example_width + pad) +
(1:example_width)) = ...
reshape(X(curr_ex, :),
example_height, example_width) / max_val;
curr_ex = curr_ex + 1;
end
if curr_ex > m,
break;
end
end
% Display Image
h = imagesc(display_array, [-1 1]);
% Do not show axis
axis image off
drawnow;
end
错误:
文件 C:\Users\ALI\displayData.m 的第 86 行附近的 displayData 解析错误
语法错误
请指导这是脚本中的错误,这个脚本已经写在 coursera 中,所以它必须没有错误。
解决方案
...
与 coursera 中的原始代码相比,您似乎已经修改了代码,并在多个位置移动了“省略号”运算符(即)或应该跟随它的行。
由于省略号运算符的点出现在一行的末尾,表示后面的行是前一行的延续,因此移动省略号或其下方的行将破坏代码。
例如
a = 1 + ... % correct use of ellipsis, code continues below
2 % treated as one line, i.e. a = 1 + 2
对比
a = 1 + % without ellipsis, the line is complete, and has an error
... 2 % bad use of ellipsis; also anything to the right of '...' is ignored
对比
a = 1 + ... % ellipsis used properly so far
% but the empty line here makes the whole 'line' `a = 1 +` which is wrong
2 % This is a new instruction
推荐阅读
- sql - 查找去年没有创建关联对象的对象
- sorting - 根据两列对行进行排序
- python - Python 字典:返回列表或字符串中的第一个值
- javascript - 使用 Mailjet 的 contactdata/contactID API 端点的问题
- fusionauth - 创建用户时,FusionAuth sendSetPasswordEmail 不发送设置密码电子邮件
- r - 特定正则表达式的正则表达式强制长度
- ios - 我收到 npm run ios 命令错误
- swift - 使用 TKSmardCard 在 iOS13 上向 SIM 卡发送 APDU 命令
- reactjs - 确保 prop 是来自常量的值 - TS
- c++ - 如何过滤双向链表?