Why Invalid or missing path error popped up when using saveas function in matlab?
13 次查看(过去 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 个评论
采纳的回答
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!