i am trying to save .mat file but its not working.

8 次查看(过去 30 天)
eval(['save D:\F' int2str(I_fno) '\A' int2str(I_D) '_' int2str(I_NP) '_' int2str(s) ' Best_mat;'])
error:
??? Error using ==> save
Unable to write file D:\F2\A240_50_1: No such file or directory.
Error in ==> Run at 53
eval(['save D:\F' int2str(I_fno) '\A' int2str(I_D) '_' int2str(I_NP) '_'
int2str(s) ' Best_mat;'])
  1 个评论
Stephen23
Stephen23 2015-10-6
编辑:Stephen23 2015-10-6
Don't use eval for such trivial code.
eval makes your life much more difficult by hiding all of the useful code hinting, warnings and error messages that you would get is you wrote code properly, without eval.
Although beginners all seem to believe that eval solves every code challenge, it actually just creates many more problems than it solves, which is exactly what you are experiencing now.
Summary: don't use eval.
Read this to know more about why it a poor programming practice:

请先登录,再进行评论。

回答(1 个)

Thorsten
Thorsten 2015-10-6
编辑:Thorsten 2015-10-6
You evaluate the string
save D:\F2\A240_50_1 Best_mat;
That is, you try to save the variable 'Best_mat' to the file A240_50_1 in directory D:\F2\
The error tells you that the directory D:\F2\ does not exist.
So you have to create it with
mkdir('D:\F2')
Don't use eval, but
filename = ['D:\F' int2str(I_fno) '\A' int2str(I_D) '_' int2str(I_NP) '_' int2str(s)];
save(filename, 'Best_mat')
  8 个评论
Muhammad Umer
Muhammad Umer 2015-10-6
this one is working
filename=['D:\F2\A' int2str(I_D) '_' int2str(I_NP) '_' int2str(s)];
save(filename, 'Best_mat');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by