How to load .txt files into MATLAB from server?

3 ビュー (過去 30 日間)
Austin Jandreau
Austin Jandreau 2020 年 2 月 14 日
コメント済み: Geoff Hayes 2020 年 2 月 18 日
Hello All, I am currently having trouble geting the data in my .txt files to be displayed in MATLAB. I can see file names, but recieve errors when i run the full code. The maindir is just three random .txt files that have one line of text which says "test" and are saved in a folder on a server. All 3 files have different names(ex. test2.txt numerouno.txt,test3.txt) Any thoughts or suggestions would be greatly appreciated.
maindir=['U:\Random\text files for matlab code test'];
cd(maindir)
textfiles=dir('*.txt');
textfiles.name
numfiles=1:length(textfiles);
mydata=cell(1,numfiles);
for k=1:numfiles
mydata(k)=importdata(textfiles(k).name);
end
data=mydata(k);
disp(mydata)

回答 (1 件)

Geoff Hayes
Geoff Hayes 2020 年 2 月 14 日
Austin - what is the error that you are observing? Is it
Error using cell
Size inputs must be scalar.
Note the code
numfiles=1:length(textfiles);
mydata=cell(1,numfiles);
where numfiles is an array with elements 1 2 3 ... up to the number of text files. I think that you want to do
numfiles=length(textfiles);
mydata=cell(1,numfiles);
instead. Also, since mydata is a cell array, you may want to try indexing with {} braces instead of () brackets
mydata{k}=importdata(textfiles(k).name);
  2 件のコメント
Austin Jandreau
Austin Jandreau 2020 年 2 月 18 日
Hello Geoff Hayes,
First up thank you for responding to my question, it is myuch appreciated.
Secondly, Yes the error ithat was seeing was the following:
Error using cell
Size inputs must be scalar.
I tried out the recommendations and recieved a new error. The new error being seen is:
??? Error using ==> text
Invalid parameter/value pair arguments
Im going to play around with the code for a bit and try a few changes to see if i can get it to work, any thoughts on the new error?
Geoff Hayes
Geoff Hayes 2020 年 2 月 18 日
Austin - I'd have to see the line of code that is generating the error message. Are you now calling the text function? Or doing something else?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by