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

14 Ansichten (letzte 30 Tage)
Andika Asyuda
Andika Asyuda am 17 Apr. 2023
Bearbeitet: Stephen23 am 17 Apr. 2023
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 Kommentar
Stephen23
Stephen23 am 17 Apr. 2023
DIR returns a structure. What do you expect READMATRIX to do with a structure as its first input argument?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 17 Apr. 2023
Bearbeitet: Stephen23 am 17 Apr. 2023
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?

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by