How to plot graph using data from a text file?

조회 수: 27 (최근 30일)
bala balu
bala balu 2019년 5월 15일
댓글: Peter Arandorenko 2020년 7월 16일
Attached is the sound.txt file and questions.
How do we plot a graph with said x and y values? i have tried this but to no success.
filename='sound.txt';
fid= fopen(filename,'r');
header = fscanf(fid,'%s',[1 1]);
headerx= fscanf(fid,'%f',[1 8]);
headery=[];
data=[];
for k= 1:24
headery= [headery; fscanf(fid,'%f',[1 1])];
data = [data; fscanf(fid,'%f',[1 8])];
end
mesh(headerx,headery,data)
Help please :)
  댓글 수: 8
Star Strider
Star Strider 2019년 5월 16일
Do you means using like X=[-10:5:25] when you meant saving it as a vector?
Yes. Although you need to read it (and the y-vector) from the file.
And can you please clarify what you meant by saving the rest as a matrics? How do you accomplish that?
The entire array will be imported as a matrix. For the rest, see the documentation section on Matrix Indexing (link).
bala balu
bala balu 2019년 5월 16일
I have successfully completed my assignment. Thanks for all the help!

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

채택된 답변

KSSV
KSSV 2019년 5월 16일
Replace y/x in the text file with NaN.
A = load('sound.txt') ;
x = A(1,2:end) ;
y = A(2:end,1) ;
Z = A(2:end,2:end) ;
figure
surf(x,y,Z)
figure
pcolor(x,y,Z)
figure
contour(x,y,Z)
  댓글 수: 3
bala balu
bala balu 2019년 5월 16일
Thank you, i managed to produce a graph with this.
Peter Arandorenko
Peter Arandorenko 2020년 7월 16일
Can you show us how it looks like?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by