Matlab undefined variable causing segmentation violation

조회 수: 1 (최근 30일)
Natalie E
Natalie E 2015년 11월 11일
편집: Adithya Addanki 2015년 12월 1일
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
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 CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by