how to do density plot?
古いコメントを表示
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 件のコメント
Adam Danz
2018 年 9 月 19 日
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
2018 年 9 月 19 日
編集済み: sourabh mittal
2018 年 9 月 19 日
Adam Danz
2018 年 9 月 19 日
I continued in the answer section though I'm unsure about the plot you're describing.
sourabh mittal
2018 年 9 月 20 日
採用された回答
その他の回答 (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 件のコメント
Adam Danz
2018 年 9 月 19 日
See comments under the answer provided by @ImageAnalyst for more interpretations of what you'd like to plot in 2D space.
カテゴリ
ヘルプ センター および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
