本周文件交换精选

我们最好的用户提交

R2016b特性:markindices, jsonencode, jsondecode

汪东城R2016b的许多新特性中有两个是本周挑选出来的:MarkerIndices属性指定标记位置jsonencode/jsondecode

在过去,我强调了一些新产品特性,这些特性与之前的精选相关:《互动传奇R 2016a》"原点经过零吗".这周的帖子也是同样的性质。

MarkerIndices

早在2013年,我就在用更少的标记创建线图.当你有一个密集的(高采样的)信号,你想用标记来绘制时,这是特别有用的。在R2016b中,您可以使用新的MarkerIndices属性指定要向哪些点添加标记。

例如,如果您想要10个等距标记,您可以执行以下操作。

t = 0:0.005:π;情节(t,罪(3 * t) * cos (t / 2)“p -”“MarkerIndices”而圆(linspace(1、长度(t) 10)))

jsonencode/jsondecode

2015年4月,我又发了一篇博客解析JSON文件.在R2016b中,我们现在有jsonencodejsondecode.我将使用我在2015年的博文中使用的相同的例子。假设我们有example.json有以下内容。

{"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适用于字符数组,因此我们将首先读取文本数据。

str = fileread (“example.json”);

然后,只需调用jsondecode

data = jsondecode (str)
data = struct with fields: firstName: 'John' lastName: 'Smith' age: 25 address: [1×1 struct] phoneNumber: [2×1 struct]

输出是一个结构。

disp (data.address)
地址:'3 Apple Hill Dr' city: 'Natick' state: 'MA' postalCode: '01760'
disp (data.phoneNumber (1))
类型:'home'号码:'123 456 7890'

评论

试试这些新功能吧。如果您正在使用pre-R2016b MATLAB,请务必查看我上面提到的博客文章。让我们知道你的想法在这里

|
  • 打印
  • 发送电子邮件

评论

要留下评论,请点击在这里登录到您的MathWorks帐户或创建一个新帐户。