How to plot graph using data from a text file?
이전 댓글 표시
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
Geoff Hayes
2019년 5월 15일
bala - what is wrong with the plot from mesh? Is that not what you are expecting?
Star Strider
2019년 5월 15일
Use readmatrix to import the file. (If you do not have readmatrix, then textscan would probably be your next most appropriate alternative.) You then have to remove the top row and the first column and save them separately (those will be your x and y coordinates respectively), and plot the rest of the matrix.
This is a MATLAB programming assignment, so it would not be appropriate to give specific help on the rest of it.
bala balu
2019년 5월 16일
bala balu
2019년 5월 16일
Star Strider
2019년 5월 16일
I believe the assignment wants you to do a contour plot. The coding for that is similar to a mesh plot.
Save the x and y values as vectors in your workspace. Save the rest of the data as a matrix.
bala balu
2019년 5월 16일
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
2019년 5월 16일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!