функция отображения данных в ex3 coursera машинного обучения - PullRequest
0 голосов
/ 09 сентября 2018

Я столкнулся с проблемой, вот мой сценарий. какой-то конец или проблема в скобках, но я проверил, что отметка отсутствует.

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

ОШИБКА:

displayData ошибка разбора возле строки 86 файла C: \ Users \ ALI \ displayData.m

синтаксическая ошибка

Руководство Pls, которое является ошибкой в ​​скрипте, этот скрипт уже написан на Coursera, поэтому его должно быть без ошибок.

1 Ответ

0 голосов
/ 10 сентября 2018

Вы, кажется, изменили код и переместили оператор "многоточие" (т.е. ...) или строку, которая должна следовать за ним, в нескольких местах по сравнению с исходным кодом в конечно.

Так как точка оператора эллипса должна появляться в конце строки, это означает, что следующая строка должна быть продолжением линии раньше, а затем перемещение многоточия или строки под ним нарушит код.

* 1006 Е.Г. *

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
...