reduce the size of figure,

 Respuesta aceptada

Jakob Sørensen
Jakob Sørensen el 17 de Abr. de 2012

0 votos

Then you are looking for some clever matrix work, rather than figure size.
Try smth like this:
wavelength = 100;
a = 1:4001;
A = repmat(a, [3001 1]);
B = 3.*(sin((1-A).*2.*pi./wavelength)) + 1003;
figure;
imagesc(B);
Takes less than a second to run on my computer and does around the same. You might have to fix the last couple of details for it to be an exact match.

Más respuestas (2)

Jakob Sørensen
Jakob Sørensen el 17 de Abr. de 2012

0 votos

Here is an example:
% Create a 1000x500 px figure, at the position x,y = 10,10 (starting at the left
% bottom corner)
superFig = figure('Position', [10 10 1000 500]);
If you want to change it for an already existing figure you just use the set function.
% Changes properties of figure named 'superFig'
set(superFig, 'Position', [10 10 1000 500]);
or
% Changes properties of current figure
set(gcf, 'Position', [10 10 1000 500]);

4 comentarios

simira atraqi
simira atraqi el 17 de Abr. de 2012
How I add this code to my codes?
I have this matrix and go slowly when I run it, I want to reduce the time with the same wavelength.
xRes = 1; % Sets the resolution (step length), in µm, along the x-axis.
yRes = 1; % Sets the resolution (step length), in µm, along the y-axis.
zRes = 1; % Sets the resolution (step length), in µm, along the z-axis.
xLength = 4000; % Sets the length of the surface in X.
yLength = 3000; % Sets the length of the surface in Y.
wavelength = 100;
f = @(x) 3*sin(x*2*pi/wavelength) + 1003; % The function for the sine wave with the
% amplitude 3 µm and wave length of about 100 µm. Mean level is
% 1003 µm.
% Prints the sine wave into a matrix:
A = zeros(yLength/yRes+1,xLength/xRes+1);
for k = 1:length(A(:,1))
for l = 1:length(A(1,:))
A(k,l) = f(l-1);
end
end
Jakob Sørensen
Jakob Sørensen el 17 de Abr. de 2012
I don't see how you get the size of a figure to affect that?
simira atraqi
simira atraqi el 17 de Abr. de 2012
figure(1);
imagesc(A);
simira atraqi
simira atraqi el 17 de Abr. de 2012
whos
Name Size Bytes Class
A 3001x4001 96056008 double array

Iniciar sesión para comentar.

Jakob Sørensen
Jakob Sørensen el 17 de Abr. de 2012

0 votos

Try this:
tic;
xRes = 1; % Sets the resolution (step length), in µm, along the x-axis.
yRes = 1; % Sets the resolution (step length), in µm, along the y-axis.
zRes = 1; % Sets the resolution (step length), in µm, along the z-axis.
xLength = 4000; % Sets the length of the surface in X.
yLength = 3000; % Sets the length of the surface in Y.
wavelength = 100;
f = @(x) 3*sin(x*2*pi/wavelength) + 1003; % The function for the sine wave with the
% amplitude 3 µm and wave length of about 100 µm. Mean level is
% 1003 µm.
% Prints the sine wave into a matrix:
A = zeros(yLength/yRes+1,xLength/xRes+1);
for k = 1:length(A(:,1))
for l = 1:length(A(1,:))
A(k,l) = f(l-1);
end
end
toc;
and then...
tic;
figure(1);
imagesc(A);
toc;
You will see that the plotting part only takes around 1/50 of the total time. What is taking so long is running a loop around 12 million times.

1 comentario

simira atraqi
simira atraqi el 17 de Abr. de 2012
yes,
Elapsed time is 294.952000 seconds.
Elapsed time is 0.141000 seconds.
but I want to reduce the time for all the program not only for the figure.

Iniciar sesión para comentar.

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by