How to implement a function slideshow to multiple figures ?

13 views (last 30 days)
I want to create a slideshow to see the figures of my data project.
I found a function slideshow() on matlab documentation but I don't know how to impleent in the code below. The loop goes trough 24 figures in csv files.
Any ideia how to implement this?
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
DataPath = '.\';
AvailableFiles = dir((fullfile(DataPath, '*.csv'))); % list available data files
fileName = 'o3_surface_20180701000000.nc';
% latData = ncread(fileName,'latitude');
for idx = 1: size(AvailableFiles,1)
OpenFileName = AvailableFiles(idx).name;
X = ncread('o3_surface_20180701000000.nc', 'lat');
Y = ncread('o3_surface_20180701000000.nc', 'lon');
% this is one hours for Cluster based ensemble data. you will 23 more
Z = csvread(OpenFileName);
X= double(X);
Y= double(Y);
%% Create a display of the data from the NetCDF files like this
[X,Y] = meshgrid(X, Y);
figure(idx);
clf
% Create the map
worldmap('europe'); % set the part of the earth to show
load coastlines
plotm(coastlat,coastlon)
land = shaperead('landareas', 'UseGeoCoords', true);
geoshow(gca, land, 'FaceColor', [0.5 0.7 0.5])
lakes = shaperead('worldlakes', 'UseGeoCoords', true);
geoshow(lakes, 'FaceColor', 'blue')
rivers = shaperead('worldrivers', 'UseGeoCoords', true);
geoshow(rivers, 'Color', 'blue')
cities = shaperead('worldcities', 'UseGeoCoords', true);
geoshow(cities, 'Marker', '.', 'Color', 'red')
% Plot the data
surfm(X, Y, Z, 'EdgeColor', 'none',...
'FaceAlpha', 0.5) % edge colour outlines the edges, 'FaceAlpha', sets the transparency
end

Accepted Answer

Sindar
Sindar on 13 Apr 2020
Edited: Sindar on 13 Apr 2020
Do you want the slideshow to exist only in Matlab, or do you want to be able to share it? Here are my personal suggestions:
If you only need it in Matlab:
At the end of each plotting loop, add a pause(2) command, modifying the delay to your tastes. You may also need drawnow before, depending on the figures:
for idx = 1: size(AvailableFiles,1)
...
surfm(X, Y, Z, 'EdgeColor', 'none','FaceAlpha', 0.5)
drawnow
pause(2)
end
If you need it outside Matlab
My experience has been that the best way to do this is to simply save the plots as separate images, and use external tools to view them.
for idx = 1: size(AvailableFiles,1)
...
surfm(X, Y, Z, 'EdgeColor', 'none','FaceAlpha', 0.5)
% save as Fig1.png, Fig2.png, ...
print("Fig"+idx,'-dpng')
end
That way, you can scroll through the images at your own rate, pausing on interesting ones. If you want it to scroll at a fixed rate, your OS probably has a way to do that. You may want to name the files more informatively, though.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!