readmatrix error: "filename" must be a string scalar or character vector.

19 次查看(过去 30 天)
Hi,
I am trying to run a code to import and analyze all .txt file in folder 0p0001nM. There should be 5 of them, and each one contains 4 columns of data. My goal is the following:
  1. extract the third column of each file
  2. Apply certain operation to the third column of files(identical operation between files)
  3. Creating a matrice, which contain all 5 columns
The code is shown below. Apparently, I failed to import any data from .txt file. The errormessage is the followng:
-------------------------------------------------
Error using readmatrix (line 158)
"filename" must be a string scalar or character vector.
Error in cvHistamine (line 5)
S(k).data=readmatrix(F);
----------------------------------------------------
Can anyone help to solve this problem ?
Andika
---------------------------------------------------------------------------------------------------------------------------------------
P='C:\Users\aasyuda\Documents\CV-EIS\aptamer-histamin\14April2023\14April2023\0p0001nM';
S=dir(fullfile(P,'*.txt'));
for k=1:numel(S)
F=dir(fullfile(P,S(k).name));
S(k).data=readmatrix(F);
end

回答(1 个)

Stephen23
Stephen23 2023-4-17
编辑:Stephen23 2023-4-17
Get rid of DIR from inside the loop.
P = 'C:\Users\aasyuda\Documents\CV-EIS\aptamer-histamin\14April2023\14April2023\0p0001nM';
S = dir(fullfile(P,'*.txt'));
for k = 1:numel(S)
F = fullfile(P,S(k).name); % get rid of DIR!!!!
S(k).data = readmatrix(F);
end
The DIR before the loop already returns a structure listing all of the .TXT files that it can find: what do you expect calling another DIR inside the loop would achieve?

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by