Why Invalid or missing path error popped up when using saveas function in matlab?

조회 수: 14 (최근 30일)
Hi everyone,
I am trying to save my current figures in a loop. i get a success running it if the saveas is not in my loop. the program also can run without the saveas. but don't know why I am getting this error message: Invalid or missing path: NO PREDICTION - RSS of LTE and WLAN network of 40 m/s.
draw = 8;
queu1;
while draw > 0
figure('Name', sprintf('NO PREDICTION - RSS of LTE and WLAN network of %.0f m/s', velocity(queu)),'units','normalized','outerposition',[0 0 1 1])
plot(distance,record_RSS_LTE(queu,:),distance,record_RSS_Wimax(queu,:),distance,record_RSS_Wimax_2(queu,:),distance,record_RSS_WLAN_1(queu,:),distance,record_RSS_WLAN_2(queu,:),...
distance,record_RSS_WLAN_3(queu,:),distance,record_RSS_WLAN_4(queu,:),distance,record_RSS_WLAN_5(queu,:),distance,record_RSS_WLAN_6(queu,:),distance,record_RSS_WLAN_7(queu,:),distance,record_RSS_WLAN_8(queu,:));
xlabel('Distance(m)');
ylabel('RSS(dBm)');
legend('LTE','WiMAX1','WiMAX2','WLAN1','WLAN2','WLAN3','WLAN4','WLAN5','WLAN6','WLAN7','WLAN8');
title(sprintf('NO PREDICTION - RSS of LTE and WLAN network of %.0f m/s', velocity(queu)));
filename = sprintf('NO PREDICTION - RSS of LTE and WLAN network of %d m/s', velocity(queu));
saveas(gcf,filename,'png');
draw=draw-1
queu=queu+1
end
  댓글 수: 4
madhan ravi
madhan ravi 2020년 6월 21일
Specify the full path where you want it to be saved.
Mark Goh
Mark Goh 2020년 6월 21일
do you mean using this one as an example?
fpath = 'D:\path1\path2';
saveas(gca, fullfile(fpath, filename), 'png');

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2020년 6월 21일
편집: John D'Errico 2020년 6월 21일
You don't tell us what OS this is running under - something that is important. We have talked much in CAB meetings about the importance of knowing what system you are using, as well as MATLAB release, etc., Knowing the system would have made my answer simpler here.
I do know that velocity(queu) must be the number 40. So filename will be the string:
filename = sprintf('NO PREDICTION - RSS of LTE and WLAN network of %d m/s', 40)
filename =
'NO PREDICTION - RSS of LTE and WLAN network of 40 m/s'
Now, you want to save a figure, as a .png image, using this command.
saveas(gcf,filename,'png');
So, let me try exactly that on my computer. Just for kicks, see if it will work? I already have the variable filename created exactly as you did.
plot(rand(5))
saveas(gcf,filename,'png')
Error using saveas (line 138)
Invalid or missing path: NO PREDICTION - RSS of LTE and WLAN network of 40 m/s
So what is MATLAB telling me? It tells me that you may be running on either a Mac or on Linux, though possibly some other OS, as long as filesep is '/' on that OS.
The file name you have created contains the / character. On a Mac, or on Limux, the path to a directory uses / to break up that path. For example:
pwd
ans =
'/Users/johnderrico1/Desktop'
And on my computer, I see that filesep is:
filesep
ans =
'/'
On a Windoze platform, it would tell me to use \ instead as the separator. Therefore I can conclude you are probably not running on a Windoze machine, because you get the same error I did.
Actually, if I swap the '/' for a '\' character I get a different error on my computer. MATLAB still does not like that filename, but I'm not currently worried about that problem. So if I change the / to a backslash on my machine, the error was different.
filename =
'NO PREDICTION - RSS of LTE and WLAN network of 40 m\s'
Finally, If I change that offending character to the letter 'X', then the saveas goes off completely without a hitch.
filename(end-1) = 'X'
filename =
'NO PREDICTION - RSS of LTE and WLAN network of 40 mXs'
plot(rand(5))
saveas(gcf,filename,'png')
Therefore, you need to be more careful about how you create the filename. Don't use / in there. Don't use \ there either.
(Sorry this was so long, but I had to be able to prove the error you made was the /, and since I did not know what system you are running on, I had to deduce that.)
  댓글 수: 5
John D'Errico
John D'Errico 2020년 6월 21일
If either is accepted as a seperator on windows, then it will generate that error if you put either character in a name.
Walter Roberson
Walter Roberson 2020년 6월 21일
The \ exists inside a sprintf() so you have to worry about sprintf rules. \s is not a valid escape character pair for sprintf. \\s would have to be used instead of \s .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 LTE Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by