How do I make a 2D graph withs dots?

조회 수: 12 (최근 30일)
Kakashi
Kakashi 2013년 12월 31일
댓글: Kakashi 2014년 1월 2일
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.

채택된 답변

Image Analyst
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
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');
Kakashi
Kakashi 2014년 1월 2일
Thanks a lot, I spent hours trying to solve this things and I couldn't done it without your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by