Problem of plotting picture and video in Linux HPC
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a Matlab program that reads data file and then create avi. files and tiff pictures. It runs without problem in window OS using R2014a but cannot run in a Linux high performance computer(HPC).
When the Matlab in Linux is started there are two warnings:
Warning: No display specified. You will not be able to display graphics on the screen.
Warning: No window system found. Java option 'Desktop' ignored.
When I run my program there are two error messages:
Error using getframe (line 53)
getframe requires a valid figure window.
Error in Density_3Dplot (line 93)
writeVideo(vid, getframe(gcf)); %get the picture and put in the avi file with
the handle "vid"
When I run the program in window, pictures are displayed one by one and the command getframe and writeVideo are used to put the pictures into the avi file. However when I run it in a node in HPC nothing can be displayed. How can I modify my program so that it can be run in a system without display? Thanks a lot.
I put my code here for your reference:
clear; close all; clc;%clear all previous data
fig = figure(1);%These two lines maximize the figure dialogue
set(fig,'Units','normalized','outerPosition',[0,0,1,1]);
fig_color='w'; fig_colordef='white';
cMap=jet(256);%set the colomap using the "jet" scale
%The following defines an alternative colormap called cMap2 (from white to red)Nmap=64;
cMin2 =[111];
cMax2 =[100];
cMap2 = zeros(Nmap,3);for i =1:Nmap;
cMap2(i,:)= cMin2*(Nmap- i)/(Nmap-1)+ cMax2*(i -1)/(Nmap-1);end
% cMap(1,:)=[111];
faceAlpha1=1;
faceAlpha2=0.65;
edgeColor1='none';
edgeColor2='none';NumBoxX=100;%box number in x direction
NumBoxY=100;%box number in y directionNumBoxZ=5;%box number in z directionFirstFile=0;%the number of the first file to be readFileInterval=400;%the number of intervals between filesLastFile=2000;%the number of the last file to be read34010ValCol=4;%indicate which column is used as value for plotting e.g. the 4th column is dis. density
[MinDis,MaxDis]=Find_MaxMin(FirstFile,FileInterval,LastFile,ValCol);%Call the function to find min and max density,used to define the range of colorbar
set(gcf,'Renderer','zbuffer');%eliminate unnecessary background and prevent stationary video -Important!
vid =VideoWriter('Evolution.avi');%Create a avi file
vid.Quality=100;
vid.FrameRate=15;
open(vid);%Open the avi file so that films can be put into it later on
for ii=FirstFile:FileInterval:LastFile%Thisfor loop controls the sequential reading of data files
ns = numel(num2str(ii));%Findout the number of digits of the number of file
switch ns %The following converts the file name so that they can be used in fopen belowcase1%it's for one digit, 1,2 etc.
filename = ['rho ' num2str(ii) '.dat'];
case 2 %it's for two digits,10,20 etc.
filename =['rho ' num2str(ii)'.dat'];case3%it's for three digits, 100,110 etc.
filename = ['rho ' num2str(ii) '.dat'];
case 4 %it's for4 digits
filename =['rho ' num2str(ii)'.dat'];case5%it's for 5 digits
filename = ['rho ' num2str(ii) '.dat'];
end
fid = fopen(filename,'r');
datacell = textscan(fid, '%f%f%f%f%f%f%f%f'); %There are 8 columns to be read so there are 8 %f
fclose(fid);
all_data = cell2mat(datacell); %converted into a matrix containing all the dis. density info. for every simulation cell
M=zeros(NumBoxX,NumBoxY,1); %create a matrix of 50x50x1,representing array of simulation cells M=zeros(NumBoxX,NumBoxY,NumBoxZ);
% % the following loops assign the dislocation density from all_data to M
for i=1:NumBoxX
for j=1:NumBoxY
for k=1:1 %for k=1:NumBoxZ Only the middle plate is shown
num=3+NumBoxZ*(j-1)+NumBoxZ*NumBoxY*(i-1);%num=k+NumBoxZ*(j-1)+NumBoxZ*NumBoxY*(i-1);
% if all_data(num,ValCol)<1e13
% all_data(num,ValCol)=0;
% end
M(i,j,k)=all_data(num,ValCol); %the ValCol column of all_data is dislocation density
end
end
end
indPatch=1:numel(M);
[F,V,C]=ind2patch(indPatch,M,'v'); %Call the function ind2patch in order to plot 3D cube with color
title('adfdadasfdasf','fontsize',20);%set title \sigma_{xx}
xlabel('y','fontsize',15);ylabel('x','fontsize',15); zlabel('z','fontsize',20); hold on;
set(get(gca,'xlabel'),'Position',[50 -10 30]); %set position of axis label
set(get(gca,'ylabel'),'Position',[-3 50 -15]);
% set(get(gca,'zlabel'),'Position',[64 190 -60]);
patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'EdgeColor','k','FaceAlpha',0.5);
axis equal; view(90,-90); axis tight; axis vis3d; grid off;
colormap(cMap);
caxis([MinDis MaxDis]); %set the range of the colorbar MinDis MaxDis %caxis([min(M(:)) max(M(:))]); %range of the colorbar according to one file only
cb = colorbar; % create the colorbar
set(get(cb,'title'),'string','dfdfdfd(m^{-2})','fontsize',20); % label the colorbar Stress (MPa)
lbpos = get(cb,'title'); % get the handle of the colorbar title
set(lbpos,'units','normalized','position',[0,1.06]);
MyAxes=gca;
set(MyAxes,'Units','Normalized','position',[0.05,0.1,0.8,0.8]);
writeVideo(vid, getframe(gcf)); %get the picture and put in the avi file with the handle "vid"
title('aaaaa','fontsize',10);%set title \sigma_{xx}
set(get(cb,'title'),'string','aaaaa(m^{-2})','fontsize',10); % label the colorbar Stress (MPa)
picturename = ['aaaaa' num2str(ii) ]; % set the name of the picture with number
print(fig,picturename,'-dtiff');%save the picture in choosen format '-djpeg' | '-dpng' | '-dtiff' | '-dpdf' | '-deps' | ...
end
close(vid); %close the avi file after putting all the films into it
0 comentarios
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!