[SOLVED] Semi-colon not supressing output
조회 수: 58 (최근 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!