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

조회 수: 14 (최근 30일)
Andika Asyuda
Andika Asyuda 2023년 4월 17일
편집: Stephen23 2023년 4월 17일
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일
DIR returns a structure. What do you expect READMATRIX to do with a structure as its first input argument?

댓글을 달려면 로그인하십시오.

답변 (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