Error using textscan Not enough input arguments.

2 views (last 30 days)
Hi I am trying to read multiple .asc file to combine it into a single file, but there is error in the coding, which is using the textread.
clc
clear
format short
[oldFileNames,PathName] = uigetfile('*.asc','Select the asc-files', 'MultiSelect','on');
oldFileNames = cellstr(oldFileNames);
c = cell(size(oldFileNames));
for k = 1:length(oldFileNames)
c{k} = textread(fullfile(PathName,oldFileNames{k}));
end
T = vertcat(c{:});
save('202301.asc','T','-ASCII');
the error is
Out of memory.
Error in textread (line 124)
[varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
Error in SMOS_nc_combine (line 20)
c{k} = textread(fullfile(PathName,oldFileNames{k}));
But, i tried to change the textread to textscan, also have error. Here is the code
clc
clear
format short
[oldFileNames,PathName] = uigetfile('*.asc','Select the asc-files', 'MultiSelect','on');
oldFileNames = cellstr(oldFileNames);
c = cell(size(oldFileNames));
for k = 1:length(oldFileNames)
c{k} = textscan(fullfile(PathName,oldFileNames{k}));
end
T = vertcat(c{:});
save('202301.asc','T','-ASCII');
%here is the error
%Error using textscan
%Not enough input arguments.
%Error in SMOS_nc_combine (line 20)
%c{k} = textscan(fullfile(PathName,oldFileNames{k}));

Accepted Answer

Abderrahim. B
Abderrahim. B on 25 Sep 2023
Hi!
An out of memory issue occurs usually when your code operates on large amounts of data or does not use memory efficiently. You can read more here.
You can work around this by using fopen for which you need to specify the encoding scheme and then call textscan. Do not forget to close the file later using fclose.
Another way to work with large data in MATLAB is to use datastores.
If you need more help, please share snaps of your files.
Let me know if these options fix the issue.
-Abderrahim
  1 Comment
MAT NIZAM UTI
MAT NIZAM UTI on 25 Sep 2023
I try to use the textscan, but I cannot solve it. Can you provide the right code ?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!