2017-12-20 6 views
-1

별도의 수치 모델링 소프트웨어 (압력 파일)에서 얻은 텍스트 데이터의 일부 2D 이미지를 플로팅 한 코드가 있습니다. 이 코드는 시간 순간 및 시각화 제한을 묻고 나를 그림으로 반환합니다.MATLAB의 png 파일에 출력 수치 저장

내가 원하는 것은 시간 간격 (2s에서 20s까지)과 "시간 단계"(1s)를 제공 할 입력을 요청하면서 시각화가 모든 수치. 그런 다음 19 자 정도의 정보를 제공해야합니다. 또한 출력을 자동으로 .png 파일로 저장하는 것이 좋을 것입니다.

편집 :

clear all; 
close all; 

flnam = 'parabolic'; 

flxxx = ([flnam,'_xx.mat']); 
flyyy = ([flnam,'_yy.mat']); 
flzzz = ([flnam,'_zz.mat']); 

xms = load(flxxx); 
yms = load(flyyy); 
zms = load(flzzz); 

xm = xms.Xp; 
ym = yms.Yp; 
zm = zms.Botlev; 

clear xms; 
clear yms; 
clear zms; 

% computational domain limits 

x10 = min(min(xm)); 
y10 = min(min(ym)); 
x20 = max(max(xm)); 
y20 = max(max(ym)); 

dspg = 0; % sponge width 

x11 = x10+dspg; 
x22 = x20-dspg; 
y11 = y10+dspg; 
y22 = y20-dspg; 

% display bottom 

zm(zm==-99) = NaN; 

zm(xm<x11|xm>x22|ym<y11|ym>y22) = NaN; 

zmin = min(min(zm)); 
zmax = max(max(zm)); 

disp(' '); 
disp(' * bathymetry visualization *') 

disp(' '); 
disp([' minimum depth : ', num2str(zmin)]); 
disp([' maximum depth : ', num2str(zmax)]); 

disp(' '); 
vvmin = input(' new minimum depth ? '); 
vvmax = input(' new maximum depth ? '); 
dvv = input(' contour interval ? '); 

figure(500); 

vv = (vvmin:dvv:vvmax); 

[cc,hh] = contourf(xm,ym,zm); 
set(hh,'LineColor','none') 
axis equal; 
axis([x11 x22 y11 y22]); 
caxis([vvmin vvmax]); 
colorbar; 

% reads surface elevation 

flwav = ([flnam,'_eta.mat']); 

e3m = load(flwav); 

disp(' '); 
disp(' '); 
disp(' * wake waves visualization *') 
disp(' '); 
kt = input(' time instant (s) '); 

kft = 0; 

while kt >= 0, 

    % get time format 

    tt = kt; 

    kft = kft + 1; 

    % hours 
    th = floor(tt/3600); 
    sth = num2str(th,'%2.2i'); % string with 2 digits (e.g. '03' instead of '3') 
    % minutes 
    tt = tt-th*3600; 
    tm = floor(tt/60); 
    stm = num2str(tm,'%2.2i'); % string with 2 digits (e.g. '03' instead of '3') 
    % seconds 
    tt = tt-tm*60; 
    ts = floor(tt); 
    sts = num2str(ts,'%2.2i'); % string with 2 digits (e.g. '03' instead of '3') 
    % thousandth of second 
    tt = tt-ts; 
    tms = round(tt*1000); 
    stms = num2str(tms,'%3.3i'); % string with 3 digits (e.g. '003' instead of '3') 
    % time string 
    hhmmss = ([sth,stm,sts,'_',stms]); 
    fig_title = ([sth,'h',stm,'min',sts,'.',stms,'s']); 

    sfield = (['Watlev_',hhmmss]); 

    yesno = isfield(e3m,sfield); 

    % if SWASH got a small error in the time stamping of fields within the "e3m" struct 
    if yesno == 0, 
     if tms == 0, 
    tms = 999; 
    if ts == 0, 
     ts = 59; 
     if tm == 0, 
      tm = 59; 
      th = th-1; 
       sth = num2str(th,'%2.2i'); % string with 2 digits (e.g. '03' instead of '3') 
     else 
      tm = tm-1 
     end 
      stm = num2str(tm,'%2.2i'); % string with 2 digits (e.g. '03' instead of '3') 
    else 
     ts = ts-1; 
    end 
     sts = num2str(ts,'%2.2i'); % string with 2 digits (e.g. '03' instead of '3') 
     else 
     tms = tms-1; 
     end 
     stms = num2str(tms,'%3.3i'); % string with 3 digits (e.g. '003' instead of '3') 
     hhmmss = ([sth,stm,sts,'_',stms]); 
     sfield = (['Watlev_',hhmmss]); 
    end 

    % surface elevation 
    em = e3m.(genvarname(sfield)); 

    em(em==-99) = NaN; 

    em(xm<x11|xm>x22|ym<y11|ym>y22) = NaN; 

    emin = min(min(em)); 
    emax = max(max(em)); 

    disp(' '); 
    disp([' minimum surface elevation : ', num2str(emin)]); 
    disp([' maximum surface elevation : ', num2str(emax)]); 

    disp(' '); 
    vvmin = input(' new minimum ? '); 
    vvmax = input(' new maximum ? '); 
    dvv = input(' contour interval ? '); 

    em(em<=vvmin) = vvmin; 

    kfig = figure(kft); 

    % set figure's size and position in the screen 
    set(kfig,'units','centimeters'); % sets units to centimeters 
    posk = get(kfig,'pos'); % to see the default values 
    xf0 = 3; % x-coordinate (in the screen) of the left lower corner 
    yf0 = 0; % y-coordinate (in the screen) of the left lower corner 
    xflen = 21; % x-length of figure 
    yflen = 21; % y-length of figure 
    set(kfig,'pos',[xf0 yf0 xflen yflen]); 

    vv = (vvmin:dvv:vvmax); 

    nc = size(vv,2); 

    my_colormap = load('bluered.cmp'); 

    [cc,hh] = contourf(xm,ym,em,vv); 
    set(hh,'LineColor','none') 
    title(fig_title); 
    axis equal; 
    axis([x11 x22 y11 y22]); 
    caxis([vvmin vvmax]); 
    colorbar; 
    colormap(my_colormap); 

    kfig = figure(kft+100); 

    % set figure's size and position in the screen 
    set(kfig,'units','centimeters'); % sets units to centimeters 
    posk = get(kfig,'pos'); % to see the default values 
    xf0 = 3; % x-coordinate (in the screen) of the left lower corner 
    yf0 = 0; % y-coordinate (in the screen) of the left lower corner 
    xflen = 21; % x-length of figure 
    yflen = 21; % y-length of figure 
    set(kfig,'pos',[xf0 yf0 xflen yflen]); 

    [cc,hh] = contour(xm,ym,em,vv); 
    set(hh,'LineColor','k') 
    title(fig_title); 
    axis equal; 
    axis([x11 x22 y11 y22]); 
    caxis([vvmin vvmax]); 

    disp(' '); 
    disp(' Next case !'); 
    disp(' '); 
    kt = input(' time instant (s) '); 

end 

% end program view_wake_2DH_mat_geral 
+0

복사하여 문제의 코드를 붙여 넣습니다, 우리가 참조하지 않는 한 우리는 당신을 도울 수있는 모든 것을 선택하고 CTRL + K.에 펀치 코드. 또한 StackOverflow [ask] 페이지의 규칙 중 하나는 다음과 같은 것을 기억하십시오. * 다른 사람들이 문제를 재현 할 수 있도록 충분한 코드를 포함하십시오. 이에 대한 도움을 받으려면 [최소한의 완전하고 검증 가능한 예제를 만드는 방법] (https://stackoverflow.com/help/mcve) *을 읽어보십시오. 그래서 코드가 길더라도, 우리는 문제가 무엇인지 재현하기에 충분합니다. 이 작업을 수행하지 않으면 귀하의 게시물이 주제를 벗어나기로 투표 할 확률이 높아집니다. – rayryeng

+0

팁 주셔서 감사! 게시물을 편집 했으므로 이제 코드를 볼 수 있습니다. –

답변

0

는 그냥 saveas function를 사용합니다. 사용 예제 :

saveas(gcf,'figure.png'); 

또는 직접 참조로 :

fig_1 = figure(); 
% your plotting... 
saveas(fig_1,'figure_1.png'); 
+0

감사합니다. 그 그림을 저장하는 부분을 저장하십시오. 시간 간격에 대한 아이디어가 있습니까? –

+0

그 부분이 내게 완전히 명확하지는 않습니다. 조금 더 자세히 설명해 주시겠습니까? –