I leave it as an exercise for you to show that snippet runs correctly using either ss or ssExtra as inputs.įor extra credit, anyone care to write the code I'd need to add to snippet to disallow inputs with an extra fields to work? I gave a hint earlier in this column.Īny thoughts on this topic? If so, enter them here. Snippet expects a struct with fields time and amplitude 'snippet expects a struct with fields time and amplitude') ~(isfield(D,'time') & isfield(D,'amplitude')) % If either D.time or D.amplitude are missing, SNIPPET errors out. % SNIPPET(D) plots data from a struct D which must contain the two fields: I now understand that I have to look at the details of the structure variables to see if the fields I need are there.
I've seen this confusion between structures, their fields, and variables, fairly regularly on Grand total is 3969 elements using 31361 bytesĪnd I see that I have ss but not ss.time because ss.time is a member of the struct but not a variable itself. I can also see what variables I do have in my workspace: whos So now let me check my variable name using the function isvarname. Looking at the help carefully, I see that the name I give must be a variable name or the name of some file So here's my next attempt.Īnd that didn't work either! What went wrong? I gave exist a string input. That didn't work because exist expects string input. so I can capture any errors and easily show them. I'll begin by trying exist, and I am placing the code inside a try-catch. Remember, we want to check to see if the input is a struct and, if so, that it has fields time and amplitude. Snippet so I can figure out what code to put into snippet to do the error checking. Let's explore how I might check our different versions of the sunspot data to see which one or ones is suitable for use with Next let's get some data that is suitable for this function ( ss and ssExtra), and some that is not ( ssBad).Ĭhecking Inputs for Suitability with snippet with exist If either D.time or D.amplitude are missing, SNIPPET errors out. SNIPPET(D) plots data from a struct D which must contain the two fields: To get started see the example and the references. To use the package you will need a basic understanding of structural SVMs. This command should learn a linear SVM separating two clouds of 2D dots. Let's look at the help for our function first: help snippet SNIPPET plots time vs. To test the installation, open MATLAB and run the bundled demo program testsvmstructlearn.m: > testsvmstructlearn. Give them enough information to correct problems without having to consult me too often. Since I intend to pass this M-file to lots of other folks, I want to write it somewhat carefully so errors the users make Suppose I'm writing an M-file to analyze data that I expect to come in a struct with two fields, named time and amplitude. Checking Inputs for Suitability with snippet with exist.