R2016b Features: MarkerIndices, jsonencode, jsondecode
Jiro‘s picks this week are two of the many new features of R2016b: MarkerIndices property for specifying marker locations and jsonencode/ jsondecode.
In the past, I’ve highlighted a couple of new product features which were related to previous Picks: “Interactive Legend in R 2016a” and “Does your origin go through zero?”. This week’s post is of the same nature.
MarkerIndices
Back in 2013, I posted this blog on creating line plots with fewer markers. This is especially useful when you have a dense (high-sampled) signal that you want to plot with markers. In R2016b, you can use the new MarkerIndices property to specify which points to add a marker to.
For example, if you want 10 evenly-spaced markers, you can do the following.
t = 0:0.005:pi; plot(t, sin(3*t).*cos(t/2), 'p-', 'MarkerIndices', round(linspace(1,length(t),10)))
jsonencode / jsondecode
In April 2015, I posted another blog on parsing JSON files. In R2016b, we now have jsonencode and jsondecode. I’ll use the same example I used in the 2015 blog post. Let’s say we have example.json the has the following content.
{ "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "3 Apple Hill Dr", "city": "Natick", "state": "MA", "postalCode": "01760" }, "phoneNumber": [ { "type": "home", "number": "123 456 7890" }, { "type": "cell", "number": "098 765 4321" } ] }
jsondecode works on character arrays, so we will first read in the text data.
str = fileread('example.json');
Then, simply call jsondecode.
data = jsondecode(str)
data = struct with fields: firstName: 'John' lastName: 'Smith' age: 25 address: [1×1 struct] phoneNumber: [2×1 struct]
The output is a structure.
disp(data.address)
streetAddress: '3 Apple Hill Dr' city: 'Natick' state: 'MA' postalCode: '01760'
disp(data.phoneNumber(1))
type: 'home' number: '123 456 7890'
Comments
Give these new features a try. If you’re using pre-R2016b MATLAB, be sure to check out the blog posts I mentioned above. Let us know what you think here.
- Category:
- Picks
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.