Section headers are formatting as comments: how to get SH working again?

31 次查看(过去 30 天)
My section headers are formatting as comments. I was editing my code and was commenting out a block. I entered "%}" in first, and it didn't comment out when I wrote the %{ above it. Since then, my section headers are not functioning. The SH have default color settings and I can't run individual sections either. Does someone know what I messed up?

采纳的回答

Steven Lord
Steven Lord 2019-8-22
You have an error in your code near the end of the file. You're missing the loop variable.
for 1:totalNumberOfFiles
Because of that error, your code is not a valid MATLAB script. Fix that error and the Editor will be able to enable section mode.
To detect this, I copied your code into MATLAB Editor and looked along the right margin of the Editor for the red line indicating Code Analyzer has detected an error.

更多回答(1 个)

AdamG2013468
AdamG2013468 2019-8-22
From the home tab, under the ENVIRONMENT panel, select preferences. Expand the "Editor/Debugger" option from the list, then go to "autoformatting".
Under the "Section Break" section, are both of the boxes checked (they should be)?
  3 个评论
AdamG2013468
AdamG2013468 2019-8-22
You may have to copy your actual code into this question for further troubleshooting. Use the code feature (alt+enter) to use MATLAB formatting.
Samuel Veith
Samuel Veith 2019-8-22
Bummer. I hope that this code doesn't reveal how bad a programmer I am!
%% 1st header
hello
%% 2nd header
% same comment format
goodbye
%% Define Variables
clc
clear java
javaaddpath('D:\Documents\MATLAB\PDFBox-0.7.3\lib\PDFBox-0.7.3.jar');
pdfdoc = org.pdfbox.pdmodel.PDDocument;
reader = org.pdfbox.util.PDFTextStripper;
%dire = 'D:\Desktop\Luxtech Sample Quotes';
%files = dir(fullfile(dire, '*.pdf')); % dir struct of all pertinent .pdf files
%n = length(files); % how many there were
%% Pull Data from PDFs
% Start with a folder and get a list of all subfolders. Use with R2016b and later.
% It's done differently with R2016a and earlier, with genpath().
% Finds and prints names of all files in that folder and all of its subfolders.
% Similar to imageSet() function in the Computer Vision System Toolbox: http://www.mathworks.com/help/vision/ref/imageset-class.html
% Initialization steps:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
% Define a starting folder.
start_path = fullfile(matlabroot, '\toolbox');
if ~exist(start_path, 'dir')
start_path = matlabroot;
end
% Ask user to confirm the folder, or change it.
uiwait(msgbox('Pick a starting folder on the next window that will come up.'));
topLevelFolder = uigetdir(start_path);
if topLevelFolder == 0
return;
end
fprintf('The top level folder is "%s".\n', topLevelFolder);
% Specify the file pattern.
% Get ALL files using the pattern *.*
% Note the special file pattern. It has /**/ in it if you want to get files in subfolders of the top level folder.
% filePattern = sprintf('%s/**/*.m; %s/**/*.xml', topLevelFolder, topLevelFolder);
filePattern = sprintf('%s/**/*.pdf', topLevelFolder); %C:\Users\Sam Work\Dropbox (LUXTECH)\LUXTECH Team Folder\Customers
allFileInfo = dir(filePattern);
% Throw out any folders. We want files only, not folders.
isFolder = [allFileInfo.isdir]; % Logical list of what item is a folder or not.
% Now set those folder entries to null, essentially deleting/removing them from the list.
allFileInfo(isFolder) = [];
% Get a cell array of strings. We don't really use it. I'm just showing you how to get it in case you want it.
listOfFolderNames = unique({allFileInfo.folder});
numberOfFolders = length(listOfFolderNames);
fprintf('The total number of folders to look in is %d.\n', numberOfFolders);
% Get a cell array of base filename strings. We don't really use it. I'm just showing you how to get it in case you want it.
listOfFileNames = {allFileInfo.name};
totalNumberOfFiles = length(listOfFileNames);
fprintf('The total number of files in those %d folders is %d.\n', numberOfFolders, totalNumberOfFiles);
% Process all files in those folders.
totalNumberOfFiles = length(allFileInfo);
% Now we have a list of all files, matching the pattern, in the top level folder and its subfolders.
A = cell(2, 2700);
if totalNumberOfFiles >= 1
for k = 1 : totalNumberOfFiles
try
% Go through all those files.
thisFolder = allFileInfo(k).folder;
thisBaseFileName = allFileInfo(k).name;
fullFileName = fullfile(thisFolder, thisBaseFileName);
% fprintf(' Processing file %d of %d : "%s".\n', k, totalNumberOfFiles, fullFileName);
[~, baseNameNoExt, ~] = fileparts(thisBaseFileName);
fprintf('%s\n', baseNameNoExt);
pdfdoc = pdfdoc.load(fullFileName);
pdfstr = reader.getText(pdfdoc); %#ok
class(pdfstr);
pdfdoc.close;
A(1,k) = num2cell(pdfstr);
A{2,k} = thisFolder;
catch
disp('error loading a file')
end
end
else
fprintf(' Folder %s has no files in it.\n', thisFolder);
end
fprintf('\nDone looking in all %d folders!\nFound %d files in the %d folders.\n', numberOfFolders, totalNumberOfFiles, numberOfFolders);
%%Export New Lines
fid = fopen('QuotesinText.txt','w')
for 1:totalNumberOfFiles
fprintf(fid,'*~*\n''customer: ''%s\n%s*~*\n\n',A{2,k} ,A{1,k});
end
fclose(all)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by