how to do density plot?
Ältere Kommentare anzeigen
suppose, I have a text file 'data.txt' that has three columns and contains output of below.
% code
fileID = fopen('data.txt','w');
for x = 0.1:0.1:10
for y = 0.1:0.1:10
z = x*y;
T = [x, y, z];
fprintf(fileID,'%f %f %f\n',T);
end
end
fclose(fileID);
Now i want to do the density plot of this data. Please help.
4 Kommentare
Adam Danz
am 19 Sep. 2018
This code writes data to your data.txt file. Option 1 is to read the file to get the data back into matlab and then do the plotting. Option 2 is to save the data within this function/script so you don't have to read it back in. Depending on what you're trying to do, you may not even need to write it to the txt file in the first place (option 3).
Secondly, you need to specify what data you want to plot. For example, do you want to plot the density of each column of T separately?
Thirdly, how would you like to represent the density? Are you looking to plot a histogram?
sourabh mittal
am 19 Sep. 2018
Bearbeitet: sourabh mittal
am 19 Sep. 2018
Adam Danz
am 19 Sep. 2018
I continued in the answer section though I'm unsure about the plot you're describing.
sourabh mittal
am 20 Sep. 2018
Akzeptierte Antwort
Weitere Antworten (1)
You can read the data back in with dmlread()
data = dlmread('data.txt', '%f');
' data' will be the [10000 x 3] matrix.
For the figure, I'm not sure if this is what you're looking for but you can try it.
figure;
imagesc(data(:,1), data(:,2), data(:,3));
colorbar
Another option
figure;
scatter(data(:,1), data(:,2), 10, data(:,3))
1 Kommentar
Adam Danz
am 19 Sep. 2018
See comments under the answer provided by @ImageAnalyst for more interpretations of what you'd like to plot in 2D space.
Kategorien
Mehr zu Scatter Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
