필터 지우기
필터 지우기

load files whith a previus specified name

조회 수: 2 (최근 30일)
Beatriz Sanchez
Beatriz Sanchez 2019년 4월 19일
댓글: Beatriz Sanchez 2019년 4월 19일
hello all,
so, I want to load a file whose name is previously specified in a variable:
alf=0
pol=1
name= [(strcat('1beatrixresult Aplha=', num2str(alf), '- p=', num2str(pol)))]
load (name)
Now, matlab gives me an error:
Error using load
Unable to read file '1beatrixresult Aplha=0- p=1'. No such file or directory.
But I know that the file does exist. In fact if I writte it like this:
load ('1beatrixresult Alpha=0- p=1')
then matlab load the file without problem. Any idea of what could be causing this error and how can I fix it? thank you before hand
  댓글 수: 2
David Wilson
David Wilson 2019년 4월 19일
편집: David Wilson 2019년 4월 19일
Works for me, but you might want to clean up your fkilenames. Try to avoid spaces, equal signs etc. Use underscore if you must.
Let's start by generating a data (.mat) file with some dummy data, and the (awkward) filename you have.
%%
clear
dummyVar = -pi; % some dummy data
save('1beatrixresult Aplha=0- p=1')
clear
Now clear the workspace, and try to reload it. Make sure that the .mat file exists though.
%% Now try to load it
clear
% form .mat data file name
alf=0;
pol=1;
name = [(strcat('1beatrixresult Aplha=', num2str(alf), '- p=', num2str(pol)))]
if ~(exist(name,'file')==2)
warning('No file found') % prudent to check
end
load(name)
disp(dummyVar)
Works for me. If you are on Windows, your filename has spaces, and that's traditionally a big no no. You need to use double quotes in DOS. You should also have a recent version of Matlab as well. Check with ver.
Of course all your (self-inflicted) problems would go away if you had a safer filename scheme.
Beatriz Sanchez
Beatriz Sanchez 2019년 4월 19일
thank you very much, you're right about my akward way of name the files. However, It was just a typo in the name variable... thank you for you time

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

채택된 답변

Jos (10584)
Jos (10584) 2019년 4월 19일
Didn't you just make a simple typo?
% Aplha vs Alpha
% | |
  댓글 수: 1
Beatriz Sanchez
Beatriz Sanchez 2019년 4월 19일
omg! and I never notied, even when I triple check that :-o
thank you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by