readmatrix error: "filename" must be a string scalar or character vector.
15 views (last 30 days)
Show older comments
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:
- extract the third column of each file
- Apply certain operation to the third column of files(identical operation between files)
- 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 Comment
Stephen23
on 17 Apr 2023
DIR returns a structure. What do you expect READMATRIX to do with a structure as its first input argument?
Answers (1)
Stephen23
on 17 Apr 2023
Edited: Stephen23
on 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?
0 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!