readmatrix error: "filename" must be a string scalar or character vector.
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stephen23
le 17 Avr 2023
DIR returns a structure. What do you expect READMATRIX to do with a structure as its first input argument?
Réponses (1)
Stephen23
le 17 Avr 2023
Modifié(e) : Stephen23
le 17 Avr 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 commentaires
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!