Matlab undefined variable causing segmentation violation
    5 views (last 30 days)
  
       Show older comments
    
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 Comment
  Adithya Addanki
    
 on 1 Dec 2015
				
      Edited: Adithya Addanki
    
 on 1 Dec 2015
  
			Hi Natalie,
Have you tried using the "getfield" instead of the "." notation. For instance: value = getfield(struct, 'field')
Thanks, Adithya
Answers (0)
See Also
Categories
				Find more on Startup and Shutdown in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
