Hello, I am beginner at MATLAB and I am trying to plot a graph by some datas from a text file but I get this error message.
These are codes that i wrote;
clc;
clear;
[names,a,b,c,d]=textread('nums.txt','%s %d %d %d %d')
T=200:20:400
CpSO2=a(1)+b(1)*T+c(1)*T.^2+d(1)*T.^3;
CpSO3=a(2)+b(2)*T+c(2)*T.^2+d(2)*T.^3;
CpO2=a(3)+b(3)*T+c(3)*T.^2+d(3)*T.^3;
CpN2=a(4)+b(4)*T+c(4)*T.^2+d(4)*T.^3;
plot(T,CpSO2)
hold on
plot(T,CpSO3)
hold on
plot(T,O2)
hold on
plot(T,N2)
Thanks for your helps.

답변 (1개)

Pulkit Goel
Pulkit Goel 2020년 6월 24일

0 개 추천

The issue maybe that your current directory of MATLAB file and the directory your 'nums.txt. files is saved are different. For this you need to specify complete path of yout file. For example:
[names,a,b,c,d]=textread('C:\Users\PULKIT\Desktop\nums.txt','%s %d %d %d %d')
In my case I saved the file on my desktop. You can see the exact path by right clicking on the file and going in Properties (in case you are using windows).

댓글 수: 7

I added the code but it still says "file not found". This is the code:
[names,a,b,c,d]=textread('C:\Users\baldan\Desktop\nums.txt','%s %d %d %d %d')
Pulkit Goel
Pulkit Goel 2020년 6월 26일
편집: Pulkit Goel 2020년 6월 26일
I tried playing around with the file a bit but couln't reproduce your error. Except when I changed file name itself like adding extra .txt while renaming file, which I don't think should be causing the issue at your end.
Maybe try creating another file with some other content, maybe at some other location and check if you are still getting the issue. Also, check if fopen is giving 'file not found' as well. It will return '-1' as output if that is the case. Also try 'importdata' to read the contents of file, to see if the issue is coming with textread command itself or there is issue with your file.
Yusuf Baldan
Yusuf Baldan 2020년 6월 27일
I changed file name "nums.txt" when I first get this error. It was "nums" at the beginning. Even I fix that, i still get the error.
Yusuf Baldan
Yusuf Baldan 2020년 6월 27일
I tried fopen, and it returned -1 like you said.
Yusuf Baldan
Yusuf Baldan 2020년 6월 27일
편집: Yusuf Baldan 2020년 6월 27일
By the way, i solved the question but it is annoying to get this error so i want to get rid of the error. I solved the question by using save-load for variables.
Image Analyst
Image Analyst 2020년 6월 27일
So is it solved (no errors), or not???
Attach 'nums.txt' if you need more help. save() and load() are fine if you're just going to use MATLAB but if you want to look at them in a text editor or some other program you might want to still save them as a text file.
Yusuf Baldan
Yusuf Baldan 2020년 6월 27일
I solved the question by another way, but i still get the error when i use textread. I attached the text file.

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

카테고리

도움말 센터File Exchange에서 Data Import and Export에 대해 자세히 알아보기

질문:

2020년 6월 23일

댓글:

2020년 6월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by