How to plot graph using data from a text file?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
bala balu
am 15 Mai 2019
Kommentiert: Peter Arandorenko
am 16 Jul. 2020
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 Kommentare
Star Strider
am 16 Mai 2019
‘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).
Akzeptierte Antwort
KSSV
am 16 Mai 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!