matlab-json
matlab-json copied to clipboard
row-major/column-major selection, selectable precsision
I try your code on mac el capitan + Matlab 2015b & 2016a in both cases my matrix data are corrupted.
Can you provide sample data that causes this and which direction you experience this?
On 10 December 2015 18:40:16 CET, thegodone [email protected] wrote:
I try your code on mac el capitan + Matlab 2015b & 2016a in both cases my matrix data are corrupted.
Reply to this email directly or view it on GitHub: https://github.com/christianpanton/matlab-json/issues/19
Hi,
here an example: M=rand(20,10); cMcol = size(M,2); index=1:cMcol; t = repmat(index,length(M),1); Mjson=zeros(size(M,1),2*cMcol); Mjson(:,1:2:end)=t; Mjson(:,2:2:end)=M;
json_matrixes=struct('demo',Mjson); Mjsondata=tojson(json_matrixes)
matrix is like this 1.0000e+00 8.9703e-02 2.0000e+00 3.6781e-01 3.0000e+00 3.7802e-02 4.0000e+00 2.6617e-01 5.0000e+00 7.7181e-01 1.0000e+00 5.5431e-01 2.0000e+00 6.1483e-01 3.0000e+00 7.9674e-01 4.0000e+00 2.9405e-01 5.0000e+00 9.1476e-01 1.0000e+00 5.0766e-01 2.0000e+00 4.2282e-01 3.0000e+00 9.2534e-01 4.0000e+00 9.4071e-01 5.0000e+00 4.9969e-01 1.0000e+00 1.9072e-01 2.0000e+00 8.5041e-01 3.0000e+00 4.4157e-01 4.0000e+00 1.2511e-01 5.0000e+00 9.6957e-02 1.0000e+00 7.4491e-01 2.0000e+00 1.9710e-01 3.0000e+00 7.7954e-01 4.0000e+00 3.4001e-01 5.0000e+00 2.2718e-01 1.0000e+00 5.3535e-01 2.0000e+00 9.5086e-01 3.0000e+00 1.5431e-01 4.0000e+00 4.3356e-01 5.0000e+00 4.1610e-01
will the output is like this (column by column) I expected to have it line by line. Is it possible ?
our method : { "demo": [ [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], [ 0.089702871421419417, 0.55431179706336153, 0.50766473034085247, 0.19071679717781531, 0.74490658771021456, 0.53534525834736835, 0.33837544311459322, 0.98230081099041666, 0.61991771063796397, 0.0085662550826157702, 0.74235314744480174, 0.45185599058589299, 0.76852511608722662, 0.86435052388961175, 0.72781340076572376, 0.53979561544397658, 0.73951892169181233, 0.67785480883178617, 0.52646944145120311, 0.70946643653050256 ], [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ], [ 0.36781231964128669, 0.61482819815984047, 0.42282459702905317, 0.85041370392197679, 0.19709993643160362, 0.95086022447790364, 0.38603605409043729, 0.16888960332685932, 0.076550496026169812, 0.094825009223043266, 0.36428489537527653, 0.55231426602315659, 0.0063572180733543204, 0.65056776355875479, 0.26353633992869896, 0.54650772662444214, 0.19143999930468181, 0.24365972118314516, 0.19309851755949425, 0.6365333540359368 ], [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ], [ 0.037802406407230094, 0.79674490224341032, 0.92533807243769917, 0.44156720832230412, 0.7795408480201127, 0.15431257834196532, 0.86890331985264191, 0.53139024501995136, 0.071462941090274956, 0.10914122025706774, 0.5130476021214343, 0.082256827780641695, 0.28534475547030358, 0.095812746419922767, 0.013067766609010545, 0.67074265618708961, 0.22543048150275491, 0.93418242588981371, 0.29040877068231552, 0.53958011684766249 ], [ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ], [ 0.2661704656136461, 0.29404741586401417, 0.9407123502208492, 0.12511190170851039, 0.34001123841741143, 0.43355699388085467, 0.71484540071467517, 0.2308511550776875, 0.81909097296031064, 0.44510031359493418, 0.67041761473086736, 0.45665914214787862, 0.34133854025521426, 0.18117731912927082, 0.40785888858089225, 0.4880130797837462, 0.74279424059861288, 0.11714576477786565, 0.72223567041520287, 0.82243622567258357 ], [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ], [ 0.77181220504834525, 0.91476310412573869, 0.49968594978849501, 0.096957216045937766, 0.22718085648896713, 0.41609909147212765, 0.3963376019531698, 0.47982802953145354, 0.5815701482627702, 0.50223507684942148, 0.02327681498211509, 0.81764694073416855, 0.09190100428975001, 0.0041380352344002613, 0.4580979471277592, 0.8115635103929475, 0.390313863972651, 0.41260657835592429, 0.5350646860561018, 0.84554968310456502 ], [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 ], [ 0.63988516461237466, 0.0060880490827153189, 0.3722539244430102, 0.6418904942224869, 0.19941422512449924, 0.89227960485677316, 0.60516421563054457, 0.025246998445240587, 0.4873068209768725, 0.4153652019174553, 0.80015359001877051, 0.011244654993980086, 0.078884314504195197, 0.54344309962179926, 0.14003180997502374, 0.14218435660091944, 0.13982267070516341, 0.36876939579603152, 0.46931873567057325, 0.15754705652302858 ], [ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 ], [ 0.41887272779903839, 0.68992099604155677, 0.38148675166160695, 0.31886991716037771, 0.49036896559148213, 0.83711630268493997, 0.92912038804814312, 0.29921894811707317, 0.84368105271734817, 0.00074395328621690293, 0.65490133658696503, 0.27680144243999172, 0.7204620577424965, 0.7894285318610692, 0.95871755211569543, 0.63645750627361564, 0.47709727197261975, 0.17356890893885957, 0.26756836122070748, 0.095552170566846839 ], [ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 ], [ 0.39460061238648225, 0.53134399649606179, 0.55750222565292984, 0.88004559450464448, 0.53782276161799059, 0.15864439684256626, 0.32536637072560648, 0.89551401778779172, 0.70654581499932756, 0.44044697390861376, 0.0033597099812585629, 0.57302530907281712, 0.54573640036035953, 0.4025000181019871, 0.78782764975406516, 0.73900858666294145, 0.84163999929634437, 0.31286099127184941, 0.22613498307277879, 0.035561627022084541 ], [ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 ], [ 0.33983771903046656, 0.50038826322045493, 0.79530584566121842, 0.33158288257258683, 0.4909742550825319, 0.1073546193054582, 0.58526401581876053, 0.75521119072794651, 0.53768395351675835, 0.20938279420816142, 0.95641368697382512, 0.129808607734894, 0.63420198169634801, 0.50252968436930578, 0.52817518723163925, 0.97035031401874505, 0.1516951044336684, 0.92161668496107108, 0.85782235706803001, 0.66155268584423632 ], [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ], [ 0.59009449606419095, 0.31151857259144144, 0.94367857176044601, 0.22320014132595556, 0.040932597891047751, 0.96552488521125124, 0.30606377657958261, 0.2496396982920458, 0.010472263599814902, 0.94648249326459466, 0.38859657980982798, 0.73013840894207149, 0.090261595909261638, 0.22867108448485107, 0.76902368185815895, 0.72712528001091337, 0.54222227196162531, 0.5178844713313443, 0.42601664119948202, 0.23346197558429749 ] ] }
I would like this output:
{"demo": [[1,0.08970287142,2,0.3678123196,3,0.03780240641,4,0.2661704656,5,0.771812205,6,0.6398851646,7,0.4188727278,8,0.3946006124,9,0.339837719,10,0.5900944961],[1,0.5543117971,2,0.6148281982,3,0.7967449022,4,0.2940474159,5,0.9147631041,6,0.006088049083,7,0.689920996,8,0.5313439965,9,0.5003882632,10,0.3115185726],[1,0.5076647303,2,0.422824597,3,0.9253380724,4,0.9407123502,5,0.4996859498,6,0.3722539244,7,0.3814867517,8,0.5575022257,9,0.7953058457,10,0.9436785718],[1,0.1907167972,2,0.8504137039,3,0.4415672083,4,0.1251119017,5,0.09695721605,6,0.6418904942,7,0.3188699172,8,0.8800455945,9,0.3315828826,10,0.2232001413],[1,0.7449065877,2,0.1970999364,3,0.779540848,4,0.3400112384,5,0.2271808565,6,0.1994142251,7,0.4903689656,8,0.5378227616,9,0.4909742551,10,0.04093259789],[1,0.5353452583,2,0.9508602245,3,0.1543125783,4,0.4335569939,5,0.4160990915,6,0.8922796049,7,0.8371163027,8,0.1586443968,9,0.1073546193,10,0.9655248852],[1,0.3383754431,2,0.3860360541,3,0.8689033199,4,0.7148454007,5,0.396337602,6,0.6051642156,7,0.929120388,8,0.3253663707,9,0.5852640158,10,0.3060637766],[1,0.982300811,2,0.1688896033,3,0.531390245,4,0.2308511551,5,0.4798280295,6,0.02524699845,7,0.2992189481,8,0.8955140178,9,0.7552111907,10,0.2496396983],[1,0.6199177106,2,0.07655049603,3,0.07146294109,4,0.819090973,5,0.5815701483,6,0.487306821,7,0.8436810527,8,0.706545815,9,0.5376839535,10,0.0104722636],[1,0.008566255083,2,0.09482500922,3,0.1091412203,4,0.4451003136,5,0.5022350768,6,0.4153652019,7,0.0007439532862,8,0.4404469739,9,0.2093827942,10,0.9464824933],[1,0.7423531474,2,0.3642848954,3,0.5130476021,4,0.6704176147,5,0.02327681498,6,0.80015359,7,0.6549013366,8,0.003359709981,9,0.956413687,10,0.3885965798],[1,0.4518559906,2,0.552314266,3,0.08225682778,4,0.4566591421,5,0.8176469407,6,0.01124465499,7,0.2768014424,8,0.5730253091,9,0.1298086077,10,0.7301384089],[1,0.7685251161,2,0.006357218073,3,0.2853447555,4,0.3413385403,5,0.09190100429,6,0.0788843145,7,0.7204620577,8,0.5457364004,9,0.6342019817,10,0.09026159591],[1,0.8643505239,2,0.6505677636,3,0.09581274642,4,0.1811773191,5,0.004138035234,6,0.5434430996,7,0.7894285319,8,0.4025000181,9,0.5025296844,10,0.2286710845],[1,0.7278134008,2,0.2635363399,3,0.01306776661,4,0.4078588886,5,0.4580979471,6,0.14003181,7,0.9587175521,8,0.7878276498,9,0.5281751872,10,0.7690236819],[1,0.5397956154,2,0.5465077266,3,0.6707426562,4,0.4880130798,5,0.8115635104,6,0.1421843566,7,0.6364575063,8,0.7390085867,9,0.970350314,10,0.72712528],[1,0.7395189217,2,0.1914399993,3,0.2254304815,4,0.7427942406,5,0.390313864,6,0.1398226707,7,0.477097272,8,0.8416399993,9,0.1516951044,10,0.542222272],[1,0.6778548088,2,0.2436597212,3,0.9341824259,4,0.1171457648,5,0.4126065784,6,0.3687693958,7,0.1735689089,8,0.3128609913,9,0.921616685,10,0.5178844713],[1,0.5264694415,2,0.1930985176,3,0.2904087707,4,0.7222356704,5,0.5350646861,6,0.4693187357,7,0.2675683612,8,0.2261349831,9,0.8578223571,10,0.4260166412],[1,0.7094664365,2,0.636533354,3,0.5395801168,4,0.8224362257,5,0.8455496831,6,0.1575470565,7,0.09555217057,8,0.03556162702,9,0.6615526858,10,0.2334619756]]}
I know that this work but ... It would be nice to have an alternative
json_matrixes=struct('demo',Mjson'); % transpose the matrix
Mjsondata=tojson(json_matrixes)
So it is correct if you transpose the matrix?
Yes but would it be possible to pass parameters to force per lines or per columns and also to set digit precision?
Envoyé de mon iPhone
Le 11 déc. 2015 à 10:38, Christian Panton [email protected] a écrit :
So it is correct if you transpose the matrix?
— Reply to this email directly or view it on GitHub.
Digit precision is left to the underlying json-c library. Afaik it is not easy to change, but I will look into it. I don't want to break compability with previous versions, regarding row-major / column-major selection, it would have to be an addon option. I will look into it.
Tagging as feature request.
Thank you
Best regards
Guillaume
Envoyé de mon iPhone
Le 11 déc. 2015 à 10:57, Christian Panton [email protected] a écrit :
Digit precision is left to the underlying json-c library. Afaik it is not easy to change, but I will look into it. I don't want to break compability with previous versions, regarding row-major / column-major selection, it would have to be an addon option. I will look into it.
Tagging as feature request.
— Reply to this email directly or view it on GitHub.