The error using "load" and "fgets" codes in MATLAB 2013a?

I just want to use "load" command and "fgets" command in same time.
fid is a txt file which contains the directories of 40 seperate file.
fid=
materialproperties/uniaxialelement1.txt
materialproperties/uniaxialelement2.txt
materialproperties/uniaxialelement3.txt
....
....
....
So i use fgets(fid) to get the directory of any file as
fgets(fid)= materialproperties/uniaxialelement2.txt
then I need the data of this file so i use" load" command
Read_Pr=load(fgets(fid))
this code work efficently in MATLAB 2014a but i have to run the code in MATLAB 2013a but i get an error.
So what can i do for running this code without any errors in MATLAB2013a?
Whats is difference in using "load" code?

댓글 수: 4

@ugur ugur: please show us the complete error message. This means all of the red text.
Error using load
Enable to read file 'materialproperties/uniaxialelement2.txt
': Invalid argument.
Error in Analyze (line 13)
Read_Pr=load(fgetl(fid));
This is the error message.
Stephen23
Stephen23 2018년 12월 29일
편집: Stephen23 2018년 12월 29일
@ugur ugur: the error message gives the filename that you are trying to use, and you can clearly see that it includes a newline at the end:
... 'materialproperties/uniaxialelement2.txt
'
This is exacty as I already described in my answer, together with the solution. If you used my answer then there would be no newline character at the end.
PS: I doubt that the error message actually says "Enable to read file".
PPS: remember to accept my answer (it answers your question) and also answers to your other questions:
When i write Read_Pr=load('materialproperties/uniaxialelement2.txt') in stead of Read_Pr=load(fgets(fid)), it works and there is no error.
But i have to use Read_Pr=load(fgets(fid)) command because this process is in a loop and repeats 20 times in a iteration. By the way, these two code serve the same purpose but why second code doesn't work although first did??

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

 채택된 답변

Stephen23
Stephen23 2018년 12월 29일
편집: Stephen23 2018년 12월 29일

0 개 추천

Use fgetl, not fgets:
Read_Pr = load(fgetl(fid))
% ^
As its help clearly states, fgets includes the newlines at the end of the line (so this will not be a valid filename) but fgetl removes the newlines (giving a valid filename).

댓글 수: 1

Thank you so much. one letter (fgetL =>fgetS) drove me crazy.
Thank for your vital help :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2018년 12월 29일

댓글:

2018년 12월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by