[SOLVED] Semi-colon not supressing output
75 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Star Strider
2022 年 10 月 1 日
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 件のコメント
Star Strider
2022 年 10 月 1 日
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.)
その他の回答 (1 件)
Image Analyst
2022 年 10 月 1 日
Make sure echo is not on. Issue this command
echo off
参考
カテゴリ
Help Center および File Exchange で Database Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!