MATLAB Answers

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

52 views (last 30 days)
Samuel Veith
Samuel Veith on 22 Aug 2019
Edited: Samuel Veith on 23 Aug 2019
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?

Accepted Answer

Steven Lord
Steven Lord on 22 Aug 2019
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.

More Answers (1)

AdamG2013468 on 22 Aug 2019
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)?
Samuel Veith
Samuel Veith on 22 Aug 2019
Bummer. I hope that this code doesn't reveal how bad a programmer I am!
%% 1st header
%% 2nd header
% same comment format
%% Define Variables
clear java
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:
% 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;
% 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
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 = {};
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
% 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
A(1,k) = num2cell(pdfstr);
A{2,k} = thisFolder;
disp('error loading a file')
fprintf(' Folder %s has no files in it.\n', thisFolder);
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});

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!