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

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 commentaires

madhan ravi
madhan ravi le 21 Juin 2020
Modifié(e) : madhan ravi le 21 Juin 2020
What happens when you feed in the figure handle to that function?
The figure will be displayed but it will not save the figure when i use saveas function. after that, error will pop-up.
Specify the full path where you want it to be saved.
do you mean using this one as an example?
fpath = 'D:\path1\path2';
saveas(gca, fullfile(fpath, filename), 'png');

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

Thank you so much!!!!!! I can run my program already. its because of the slash '/'. I being trying to find an answer. and this platform is my last resort. Finally i can do my final project. and yeah sorry, it was my first time asking question here. I am using Windoze btw
I could not test to see what error message a Windoze system would offer, but apparently it is still the same as what I got on a Mac. Regardless, it is unfortunate how something as simple as an inadvertantly used character in a file name can trip you up.
I'm happy to hear it works now. :)
/ and \ are both accepted as path separators by windows. / is what is used internally and \ is used for presentation.
If either is accepted as a seperator on windows, then it will generate that error if you put either character in a name.
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 .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur LTE Toolbox dans Centre d'aide et File Exchange

Produits

Version

R2020a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by