Undefined Variable error for a variable that is already defined?

1 回表示 (過去 30 日間)
Natha Davis
Natha Davis 2020 年 7 月 24 日
コメント済み: Arthur Roué 2020 年 7 月 24 日
Hello all,
I have this code that I have been running to process DICOM images. I previously used it to process two folders (with the same folder structure, just diff name) successfully. Now all of a sudden I get this error "Unrecognized function or variable 'a'. Error in PrintProtocol (line 82) for i=1:size(a,1)". PrintProtocol is a function written by a mentor and I am not the author.
Going to line 82 of PrintProtocol I see this: "for i=1:size(a,1)
cd([foldersin{1} imgfolder slash a(i).name]);"
'a' is defined above in line 60 as "for i=1:size(d,1)
if (d(i).isdir == 1 && length(d(i).name) > 2)
a(l,1) = d(i,1);".
I am confused why it would work previously and then stop working now. To me a is defined in line 60, but am I missing something? I am happy to provide additional details. Thank you for your help.
  3 件のコメント
Fangjun Jiang
Fangjun Jiang 2020 年 7 月 24 日
It is inside an "if" statement. It may not be assigned if condition is not met. Put a break point on line 82 and run it again to check the value of a.
Natha Davis
Natha Davis 2020 年 7 月 24 日
I put a breakpoint at line 60 and I am still seeing it saying a is an unknown variable. Is there something different I should be doing to define a? I looked above and 'l=1', but I don't see anywhere it specifically says "a=" so maybe a isn't really defined. But if that is true, why did this work for 2 other folders?

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

採用された回答

Arthur Roué
Arthur Roué 2020 年 7 月 24 日
a is defined in a if statement.
if (d(i).isdir == 1 && length(d(i).name) > 2)
If it's false, either d is not a dir or is name is juste 1 charater, a won't be define. Are you sure your folders path are correct ?
  14 件のコメント
Natha Davis
Natha Davis 2020 年 7 月 24 日
Yea it ended up being another function that is used before printprotocol that wasn't doing its job. Thank you for your help!
Arthur Roué
Arthur Roué 2020 年 7 月 24 日
You're welcome ;)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by