|
On May 15, 4:54 pm, "Fero " <secur...@kinanitra.sk> wrote:
> I hoped, that there is a way how to draw the graph with the axis like in my picture, that there will be the axis from -1 to 1 with x/R and y/R and that it will be possible to draw there this kind of data from the matrix sigma(a,b).
> Can you help me how to make such a graph with axis like I mentioned ?
----------------------------------------------------------
Fero:
I don't think your code is giving the "spread" of the function like
your example, yours seems more compacted into the points near the
perimeter and doesn't spread out into the interior as much. In fact
there are large areas that don't change much as all, at least they
don't change by 1/256 so that the colormap isn't able to distinguish
them by color.
Nonetheless I did the best I could. Try the code below:
(Feel free to experiment around with the color map.)
% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.
% function test1
% function test1()
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
sigma=zeros(1249,1249);
a=0;
for x=-0.0624:0.0001:0.0624;
a=a+1;
b=0;
for y=-0.0624:0.0001:0.0624;
b=b+1;
P=6E-4;
R=0.0625;
t=1;
beta1=((R-y)^2+x^2);
beta2=((R+y)^2+x^2);
sigma(a,b)=(-2*P/(pi*t))*((x^2)*(R-y)/(beta1^2)+(x^2)*(R+y)/
(beta2^2)-1/(2*R));
end
end
imshow(sigma, []);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
colormap(lines);
minValue = min(min(sigma))
maxValue = max(max(sigma))
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = size(sigma, 2);
imageSizeY = size(sigma, 1);
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = imageSizeX/2;
centerY = imageSizeY/2;
radius = imageSizeX/2;
circlePixels = sqrt((rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2) <= radius;
% circlePixels is a 2D "logical" array.
% Now, display it.
% image(circlePixels) ;
% colormap([0 0 0; 1 1 1]);
% title('Binary image of a circle');
% Or, assign values outside the circle.
newGrayLevelOutside = minValue;
sigma(~circlePixels) = newGrayLevelOutside ;
% Transpose it to be like his figure.
sigma = sigma';
imshow(sigma, []);
axis on;
cMap = [gray(224);jet(32)];
cMap(1, :) = [0 0 0];
colormap(cMap);
colorbar;
title('Demo for Fero, by ImageAnalyst', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off');
% Set up tick marks.
numberOfTickMarks = 9
xTicks = linspace(1, imageSizeX, numberOfTickMarks);
yTicks = linspace(1, imageSizeX, numberOfTickMarks);
xTicksCal = linspace(-.0624,0.0624, numberOfTickMarks);
yTicksCal = linspace(-.0624,0.0624, numberOfTickMarks);
set(gca,'XTick', xTicks);
set(gca,'YTick', yTicks);
for tickMark = 1 : numberOfTickMarks
caTickLabelsX{tickMark} = sprintf('%8.5f', xTicksCal(tickMark));
caTickLabelsY{tickMark} = sprintf('%8.5f', yTicksCal(tickMark));
end
set(gca,'XTickLabel',[caTickLabelsX]);
set(gca,'YTickLabel',[caTickLabelsY]);
grid on;
msgbox('done');
|