[SOLVED] Semi-colon not supressing output

I know it's a common question here about supressing output, but I can't seem to find a missing semi-colon in my code, but yet I have a matrix displayed everytime.
The issue seems to be with the last two functions, namely table2array and readtable. This would be a minor issue if I had to import a small database, but I have hundreds of files and clc-ing everytime is just not efficient if I want to trace-back my progress.
I've attached a txt file that you can use to test the function with.
If it turns out to be a missing semi-colon, I will humbly apologize with a MATLAB Haiku 俳句。
Edit: When calling the function, I add a semi-colon.
Edit: The Issue was a semi-colon. As promised, here is my Haiku:
I was not a fool
Until semi-colon came,
Now I am a fool
function EEM = importData(filename)
%IMPORTFILE Import data from a text file
% EEM = IMPORTFILE(FILENAME) reads data from text file FILENAME for the
% default selection. Returns the numeric data.
%
% EEM = IMPORTFILE(FILE, DATALINES) reads data for the specified row
% interval(s) of text file FILENAME. Specify DATALINES as a positive
% scalar integer or a N-by-2 array of positive scalar integers for
% dis-contiguous row intervals.
%
% Example:
% EEM = importfile("C:\Users\user\Documents\Flurine\FL_DATASET\ind944h-3
% .txt", [18, Inf]);
%
% See also READTABLE.
%
% Auto-generated by MATLAB on 01-Oct-2022 12:27:26
%% Input handling
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [18, Inf];
end
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 102);
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = "\t";
% Specify column names and types
opts = setvartype(opts,"double");
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Import the data
EEM = readtable(filename, opts);
%% Convert to output type
EEM = table2array(EEM);
end

 Accepted Answer

I do not see any missing semicolons in the file, so the most likely problem is that there is one missing when you call the function (added here):
EEM = importData(filename);
Without your code, I cannot be certain that is the problem.

6 Comments

I can assure you that I've added
EEM = importData(filename);
Perhaps there’s a missing semicolon somewhere else. I don’t see it in anything you¹ve posted.
This is how the function is called in my script
% The only relevant variables in regards to the function in my script
dinfo = dir('*.txt');
fileName = dinfo.name;
% Function causing problems
Matrix = importData(fileName);
Perhaps this line (in this Comment) —
% Extract EEM, Excitation and Emission Spectrum
emissionSpectrum = Matrix(2:end,1);
excitationSpectrum = Matrix(1,2:end);
EEM = Matrix(2:end,2:end) % <— MISSING SEMICOLON
I do not see any others missing. If supplying that semicolon solves the problem, please confirm it.
If not, we need to keep looking...
.
My Haiku as promised:
I was not a fool
Until semi-colon came,
Now I am a fool
Thank you!
Nothing foolish at all! You were simply so used to looking at your code that you didn’t see that line for what it was. Not having that familiarity with it, I found it. (This is the reason newspaper and other publishers hire proofreaders and copy editors.)

Sign in to comment.

More Answers (1)

Make sure echo is not on. Issue this command
echo off

6 Comments

Then we might need all your code to try to reproduce it, because, like @Star Strider and you said, you have semicolons after every line so they should not be echoing to the command window.
Is the whole line of code being echoed (like "echo on") or is just the results of the line being printed to the command window, like "ans = " or "opts =".
Here is the function that calls the function
function [database] = assembler(DIRECTORIES)
if(isa(DIRECTORIES,'struct'))
database = DIRECTORIES;
return
end
dictionary = load('dictionary.mat');
k=1;
for i=1:DIRECTORIES.length
cd(DIRECTORIES(i));
dinfo = dir('*.txt');
for j=1:length(dinfo)
fileName = dinfo(j).name;
abbreviation = fileName(1:3);
concentration = fileName(4:6);
unitPrefix = fileName(7);
% Name
index = find(dictionary.substanceNameabbreviation == abbreviation);
sunbstanceName = dictionary.substanceName(index);
% Concentration
index = find(dictionary.unitPrefix == unitPrefix);
unit = dictionary.unit(index);
concentration = str2num(concentration) * unit;
% Import ASCII Data
Matrix = importData(fileName);
% Extract EEM, Excitation and Emission Spectrum
emissionSpectrum = Matrix(2:end,1);
excitationSpectrum = Matrix(1,2:end);
EEM = Matrix(2:end,2:end)
database(k).sunbstanceName = sunbstanceName;
database(k).abbreviation = abbreviation;
database(k).concentration = concentration;
database(k).emissionSpectrum = emissionSpectrum;
database(k).excitationSpectrum = excitationSpectrum;
database(k).EEM = EEM;
database(k).path = DIRECTORIES(i);
database(k).fileName = fileName;
k = k+1;
end
end
%clc
end
Attached is what I've got.
Evidently you've got your own importData function. Or did you just misspell the built in importdata. Please include that function.
Also you forgot to attach 'dictionary.mat'
Please give me one .m file with all the functions in it that actually runs.
I was hoping this would be a simpler problem. Thank you for taking the time.
I've included the zip file with all functions and datasets you could use to conduct your test. Since I started with it today, it's a bit baron of comments (really, sorry).
The main file is "Flurine" and all you have to do is run it. It will prompt a uigetdir, at which point you should select the database folder that I provided you in the zip. Afterwards you'll notice that upon importing, in the livetex file you'll have all 30-ish matrices displayed in sequence.
Looks like @Star Strider solved it for you so I'm not going to do anything more.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!