How do I make a 2D graph withs dots?
12 ビュー (過去 30 日間)
古いコメントを表示
I have for every latitude and longitude a point of data. I need to make a colored dot map that shows how my data is changing over the latitude and longitude.
0 件のコメント
採用された回答
Image Analyst
2013 年 12 月 31 日
Did you try the plot() or scatter() function?
x=rand(40,1);
y = rand(40,1);
plot(x, y, 'b.', 'MarkerSize', 30);
grid on;
8 件のコメント
Image Analyst
2014 年 1 月 1 日
Just as I thought, you can't use scatter. Way way too many points. You have every single lat and long in a meshgrid fashion. So in that case you should do an image. See the attached code. It will produce an image like the below for every column:

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
% Read in workbook.
folder = 'D:\Temporary stuff';
baseFileName = 'Matlab w.xlsx';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
[num, txt, raw] = xlsread(fullFileName);
% Convert NaN's to 100 - those were Total or Natural cells.
num(isnan(num)) = 100;
x = num(:,1);
y = num(:,2);
maxx = max(x);
minx = min(x);
maxy = max(y);
miny = min(y);
% Create an image
columns = int32(maxx - minx)
rows = int32(maxy - miny)
indexedImage = zeros(rows, columns, 'uint8');
for col = 3 : 14
% scatter(x, y); % No GOod!!!
% Turn into an image
for k = 1 : length(x)
% Get the value in row k, column 3
value = num(k, col);
column = int32(x(k) - minx)+1;
row = int32(y(k) - miny)+1;
indexedImage(row, column) = int32(value);
end
% Display the image.
cla;
imshow(indexedImage, []);
% Apply a colormap.
colormap(jet(101));
colorbar();
axis on;
caption = sprintf('Column %d', col);
title(caption, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Ask user if they want to continue.
promptMessage = sprintf('Showing %s.\nDo you want to Continue processing,\nor Cancel to abort processing?', caption);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
break;
end
end
msgbox('Done with demo');
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Geographic Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!