Matlab undefined variable causing segmentation violation
1 回表示 (過去 30 日間)
古いコメントを表示
I have a script I wrote, which essentially compares values from an excel sheet to a simulink model. The issue i'm having is that for some reason it started crashing matlab. I'm getting two errors consistently.
1) The more basic of the two. Whats actually crashing is inside of a try statement, and when it crashes, I get an error in Matlab saying "undefined function or variable 'caughtErr'. Below is my code
typefieldname = 'somefieldname';
guideCals(1) = structureGuide(guideData(1), gfieldname, typefieldname); %where guideData is a structured array from excel
for index = 2: size(guideData,2)
try
temp = structureGuide(guideData(index), gfieldname, typefieldname);
catch caughtErr
fprintf('%s\n', caughtErr.message); %ERROR - says caughtErr is undefined
end
end
2) The second issue has to deal with calling structureGuide, it says typefieldname is undefined in the function
function structureGuide(data, gfieldname, typefieldname)
val = data.(typefieldname); %this crashes due to undefined 'typefieldname' (even though its clearly defined) (and is defnintely in the structure)
end
I'm at a loss. If i just run the script it causes Matlab to crash with a segmentation violation but if i run it in the command window it works fine, but if i run it with the debugger enabled it crashes with issue 2.
It should be noted i'm using Matlab 2007b.
Update: If i comment out the try catch it completes. There are a bunch of warnings on the screen through (but shouldn't the try/catch ignore warnings?)
1 件のコメント
Adithya Addanki
2015 年 12 月 1 日
編集済み: Adithya Addanki
2015 年 12 月 1 日
Hi Natalie,
Have you tried using the "getfield" instead of the "." notation. For instance: value = getfield(struct, 'field')
Thanks, Adithya
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!