Matlab does not give the right answer

2 ビュー (過去 30 日間)
Phong Pham
Phong Pham 2012 年 11 月 19 日
I have a code to load the files in the folder with filename_2,

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 19 日
Check if your file filename_2 exist in your folder
  1 件のコメント
Phong Pham
Phong Pham 2012 年 11 月 19 日
it does

サインインしてコメントする。


Ilham Hardy
Ilham Hardy 2012 年 11 月 19 日
Seems for me it has more to do with
for run= 2:2
and
for run= 1:1
  1 件のコメント
Ilham Hardy
Ilham Hardy 2012 年 11 月 19 日
編集済み: Ilham Hardy 2012 年 11 月 19 日
Use the debugger and check what are the value of
run
and
ic
And what if you use only the command without any for loop.

サインインしてコメントする。


Image Analyst
Image Analyst 2012 年 11 月 19 日
編集済み: Image Analyst 2012 年 11 月 19 日
Not really sure - maybe it's a conflict between using the command line version of load and the function version (do you even know the difference?) Do you really have an equal sign in the filename, and no extension (such as .mat) for it, and that filename_2 is the actual filename and not the variable name? Anyway, assuming that's the case, try this more robust code:
for run = 2:2
for ic = 11:12
if ic == 11
fullFileName = fullfile(pwd, 'filename_2');
else
fullFileName = fullfile(pwd, 'filename_2_eps=1');
end
if exist(fullFileName, 'file')
load(fullFileName)
else
message = sprintf('Error: file not found:\n%s', fullFileName);
uiwait(warndlg(message));
end
end
end
Or maybe it's the fact that you're using run as a variable name but MATLAB considers it a built-in function name (so you should not use run as a variable name, just like you shouldn't use for, while, sprintf, load, etc. as variable names either).
  4 件のコメント
Image Analyst
Image Analyst 2012 年 11 月 19 日
I don't know what the second sentence means. What does "not right" mean to you? Also, there were 7 questions in my prior comment and you answered only 2 of them, at most.
Walter Roberson
Walter Roberson 2012 年 11 月 26 日
Your loop is overwriting X0in on each iteration, it appears.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by