Clear Filters
Clear Filters

Why my matlab can't show and save images?

2 views (last 30 days)
Beatrice
Beatrice on 31 May 2024
Commented: Beatrice on 31 May 2024

clear all; clc %------------------------Menentukan Parameter---------------% L=2000; % panjang kanal(m) T=3600; % lama simulasi (s) dx=20; % lebar grid (m) ln=0:dx:L; y=length(ln); % panjang grid n=L/dx; % jumlah grid dt=2; t=0:dt:T; var=length(t); % panjang waktu u1=-0.245; u2=0.215; pc=75; % polutan kontinu pdc=100; % polutan diskontinu

%-----------------Menentukan Domain-------------------% %skenario 1 (u1 polutan kontinu) kk1=zeros(var,y); % nilai awal kk1(:,15)=pc; % nilai konsentrasi polutan kontinu

%skenario 2 (u2 polutan kontinu) kk2=zeros(var,y); % nilai awal kk2(:,15)=pc; % nilai konsentrasi polutan kontinu

%skenario 3 (u1 polutan diskontinu) kd1=zeros(var,y); % nilai awal kd1(19,11)=pdc; % nilai konsentrasi polutan kontinu

%skenario 4 (u2 polutan diskontinu) kd2=zeros(var,y); % nilai awal kd2(19,11)=pdc; % nilai konsentrasi polutan kontinu

%----------------Perhitungan Upstream---------------%

%%---skenario 1 dan 3 (untuk polutan u1)-----%% lam1=(dt/(2*dx)); % konstanta untk numerik untuk polutan u1

if(-1<=lam1<=1); % syarat perhitungan upstream disp('Model Jalan'); else return end

%%% u1 kontinu for np=1:var-1; % looping waktu for i=2:y-1; % looping ruang a=u1-abs(u1); b=kk1(np,i+1)-kk1(np,i); c=u1+abs(u1); d=kk1(np,i)-kk1(np,i-1); kk1(np+1,i)=kk1(np,i)-lam1*((a*b)+(c*d)); end; kk1(:,15)=pc; kk1(np,1)=kk1(np,2); %nilai batas kiri kk1(np,y)=kk1(np,y-1); %niai batas kanan end;

%%% u1 diskontinu for np=1:var-1; % looping waktu for i=2:y-1; % looping ruang a=u1-abs(u1); b=kd1(np,i+1)-kd1(np,i); c=u1+abs(u1); d=kd1(np,i)-kd1(np,i-1); kd1(np+1,i)=kd1(np,i)-lam1*((a*b)+(c*d)); end; kd1(19,11)=pc; kd1(np,1)=kd1(np,2); kd1(np,y)=kd1(np,y-1); end;

%%-----------skenario 2 dan 4 (untuk polutan u2)-------------%

%%% u2 kontinu for np=1:var-1; % looping waktu for i=2:y-1; % looping ruang a=u2-abs(u2); b=kk2(np,i+1)-kk2(np,i); c=u2+abs(u2); d=kk2(np,i)-kk2(np,i-1); kk2(np+1,i)=kk2(np,i)-lam1*((a*b)+(c*d)); end; kk2(:,15)=pc; kk2(np,1)=kk2(np,2); kk2(np,y)=kk2(np,y-1); end;

%% u2 diskontinu for np=1:var-1; % looping waktu for i=2:y-1; % looping ruang a=u2-abs(u2); b=kd2(np,i+1)-kd2(np,i); c=u2+abs(u2); d=kd2(np,i)-kd2(np,i-1); kd2(np+1,i)=kd2(np,i)-lam1*((a*b)+(c*d)); end; kd2(19,11)=pc; kd2(np,1)=kd2(np,2); kd2(np,y)=kd2(np,y-1); end;

%---------------ploting--------------------% timev=[300 600 900 1200 1500]; tiv=[5 25 50 75 100];

%ploting u1 kontinu figure(17); plot(t,kk1(:,tiv(1)),t,kk1(:,tiv(2)),t,kk1(:,tiv(3)),t,kk1(:,tiv(4)),t,kk1(:,tiv(5))); xlabel('waktu (s)');ylabel('konsentrasi'); legend('100 m','500 m','1000 m','1500 m','2000 m'); title('Grafik Perubahan Konsentrasi Terhadap waktu untuk u1 polutan kontinu dengan metode Upstream'); set(17,'Position',get(0,'Screensize')); saveas(17,'Grafik Perubahan Konsentrasi terhadap Waktu untuk u1 Polutan Kontinu dengan Metode Upstream.jpg');

figure (18); plot(ln,kk1(timev(1),:),ln,kk1(timev(2),:),ln,kk1(timev(3),:),ln,kk1(timev(4),:),ln,kk1(timev(5),:)), xlabel('Kanal');ylabel('Konsentrasi'); legend('600 s','1200 s','1800 s','2400 s','3000 s'); title('Grafik Perubahan Konsentrasi Terhadap Ruang untuk u1 Polutan Kontinu dengan Metode Upstream'); set(18,'Position',get(0,'Screensize')); saveas(18,'Grafik Perubahan Konsentrasi terhadap ruang untuk u1 Polutan Kontinu dengan Metode Upstream.jpg');

%%Ploting u2 kontinu figure(19); plot(t,kk2(:,tiv(1)),t,kk2(:,tiv(2)),t,kk2(:,tiv(3)),t,kk2(:,tiv(4)),t,kk2(:,tiv(5))); xlabel('waktu (s)');ylabel('konsentrasi'); legend('100 m','500 m','1000 m','1500 m','2000 m'); title('Grafik Perubahan Konsentrasi Terhadap waktu untuk u2 Polutan Kontinu dengan Metode Upstream'); set(19,'Position',get(0,'Screensize')); saveas(19,'Grafik Perubahan Konsentrasi terhadap Waktu untuk u2 Polutan Kontinu dengan Metode Upstream.jpg');

figure(20); plot(ln,kk2(timev(1),:),ln,kk2(timev(2),:),ln,kk2(timev(3),:),ln,kk2(timev(4),:),ln,kk2(timev(5),:)), xlabel('Kanal');ylabel('Konsentrasi'); legend('600 s','1200 s','1800 s','2400 s','3000 s'); title('Grafik Perubahan Konsentrasi Terhadap Ruang untuk u2 Polutan Kontinu dengan Metode Upstream'); set(20,'Position',get(0,'Screensize')); saveas(20,'Grafik Perubahan Konsentrasi terhadap Ruang untuk u2 Polutan Kontinu dengan Metode Upstream.jpg');

%%ploting u1 diskontinu figure(21); plot(t,kd1(:,tiv(1)),t,kd1(:,tiv(2)),t,kd1(:,tiv(3)),t,kd1(:,tiv(4)),t,kd1(:,tiv(5))); xlabel('waktu (s)');ylabel('konsentrasi'); legend('100 m','500 m','1000 m','1500 m','2000 m'); title('Grafik Perubahan Konsentrasi Terhadap waktu untuk u1 Polutan diskontinu dengan Metode Upstream'); set(21,'Position',get(0,'Screensize')); saveas(21,'Grafik Perubahan Konsentrasi terhadap Waktu untuk u1 Polutan diskontinu dengan Metode Upstream.jpg');

figure(22); plot(ln,kd1(timev(1),:),ln,kd1(timev(2),:),ln,kd1(timev(3),:),ln,kd1(timev(4),:),ln,kd1(timev(5),:)), xlabel('Kanal');ylabel('Konsentrasi'); legend('600 s','1200 s','1800 s','2400 s','3000 s'); title('Grafik Perubahan Konsentrasi Terhadap Ruang untuk u1 Polutan diskontinu dengan Metode Upstream'); set(22,'Position',get(0,'Screensize')); saveas(22,'Grafik Perubahan Konsentrasi terhadap Ruang untuk u1 Polutan diskontinu dengan Metode Upstream.jpg');

%%ploting u2 diskontinu figure(23); plot(t,kd2(:,tiv(1)),t,kd2(:,tiv(2)),t,kd2(:,tiv(3)),t,kd2(:,tiv(4)),t,kd2(:,tiv(5))); xlabel('waktu (s)');ylabel('konsentrasi'); legend('100 m','500 m','1000 m','1500 m','2000 m'); title('Grafik Perubahan Konsentrasi Terhadap waktu untuk u2 Polutan diskontinu dengan Metode Upstream'); set(23,'Position',get(0,'Screensize')); saveas(23,'Grafik Perubahan Konsentrasi terhadap Waktu untuk u2 Polutan diskontinu dengan Metode Upstream.jpg');

figure(24); plot(ln,kd2(timev(1),:),ln,kd2(timev(2),:),ln,kd2(timev(3),:),ln,kd2(timev(4),:),ln,kd2(timev(5),:)), xlabel('Kanal');ylabel('Konsentrasi'); legend('600 s','1200 s','1800 s','2400 s','3000 s'); title('Grafik Perubahan Konsentrasi Terhadap Ruang untuk u2 Polutan diskontinu dengan Metode Upstream'); set(24,'Position',get(0,'Screensize')); saveas(24,'Grafik Perubahan Konsentrasi terhadap Ruang untuk u2 Polutan diskontinu dengan Metode Upstream.jpg');

when i tried to run it appear error like this

Warning: File './Grafik Perubahan Konsentrasi terhadap Waktu untuk u2 Polutan diskontinu dengan Metode Upstream.jpg' not found. > In matlab.graphics.internal.name (line 108) In print (line 71) In saveas (line 181) In UpStreamTUGAS (line 166) Error using print (line 90) Output file './Grafik Perubahan Konsentrasi terhadap Waktu untuk u2 Polutan diskontinu dengan Metode Upstream.jpg' was not created. The file name may not be valid.

Error in saveas (line 181) print( h, name, ['-d' dev{i}] )

Error in UpStreamTUGAS (line 166) saveas(23,'Grafik Perubahan Konsentrasi terhadap Waktu untuk u2 Polutan diskontinu dengan Metode Upstream.jpg');

Answers (1)

Sarthak
Sarthak on 31 May 2024
Hi Beatrice,
It would be much better if you could share your script file or atleast paste a formatted script.
This might help!
For the error message, it indicates that there's an issue with saving the figures as images. It looks like the issue is with the filename not matching exactly.
The error has a 'd' while I think it should be 'D'. Not sure if you have hand-typped it or it is the actual issue. Generally these issues arise due to invalid file names or not having write permissions. But in your case it looks like the filename not matching.
Cheers!
  1 Comment
Beatrice
Beatrice on 31 May 2024
Thank you so much for your answer, i will follow the suggestion and find the problem

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!