Error using textscan Not enough input arguments.

2 次查看(过去 30 天)
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}));

采纳的回答

Abderrahim. B
Abderrahim. B 2023-9-25
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

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by