How to fill a uitable with data in 1xn cell (n 1x1 structs)?
Ältere Kommentare anzeigen
Hello,
I'm a newbie to MatLab and I started a project to get data from an online REST API
Using urlread2 I retrieved the data:
header = http_createHeader('Authorization','Bearer XXXXXXXXXXXXXXXXXX-YYYYYYYYYYYYYYYYY')
url = 'https://api-fxpractice.oanda.com/v1/accounts'
testvar = urlread2 (url,'GET','',header)
so I got in testvar the json data...
testvar:
'{
"accounts" : [
{
"accountId" : 1125870,
"accountName" : "Primary",
"accountCurrency" : "EUR",
"marginRate" : 0.05
},
{
"accountId" : 9244246,
"accountName" : "Bull",
"accountCurrency" : "EUR",
"marginRate" : 0.02
},
{
"accountId" : 6955195,
"accountName" : "Bear",
"accountCurrency" : "EUR",
"marginRate" : 0.02
},
{
"accountId" : 1614502,
"accountName" : "MT4_EUR_Practice",
"accountCurrency" : "EUR",
"marginRate" : 0.05,
"accountPropertyName" : [
"MT4"
]
},
{
"accountId" : 9995814,
"accountName" : "Coaching",
"accountCurrency" : "EUR",
"marginRate" : 0.02
}
]
}'
I want to represent this data in a clickable uitable with one row per each account ( in this example 5 rows) and 4 columns: accountId, accountName, accountCurrency and marginRate.
(when a row has 5 fields (see the 4th account in this example accountID 1614502) the 5th field should be skipped)
First I used parse_json:
test_A = parse_json(testvar)
test_A is a 1x1 cell containing 1x1 struct.
To get rid of the cell I used:
test_B = test_A{1,1}
test_B is a 1x1 struct with 1 field named accounts and containing 1x5 cell (the size of the cell will change depending on the data received)
to get rid of the struct I used:
test_C = struct2cell(test_B)
test_C is a 1x1 cell containing one 1x5 cell, to reveal the 1x5 cell I used:
test_D=test_C{1,1}
test_D is a 1x5 cell containing in this example five 1x1 structs each with 4 or 5 fields
cell 1,1:
accountId: 1125870
accountName: 'Primary'
accountCurrency: 'EUR'
marginRate: 0.0500
cell 1,2:
accountId: 9244246
accountName: 'Bull'
accountCurrency: 'EUR'
marginRate: 0.0200
cell 1,3:
accountId: 6955195
accountName: 'Bear'
accountCurrency: 'EUR'
marginRate: 0.0200
cell 1,4:
accountId: 1614502
accountName: 'MT4_EUR_Practice'
accountCurrency: 'EUR'
marginRate: 0.0200
accountPropertyName: 1x1 cell
cell 1,5:
accountId: 9995814
accountName: 'Coaching'
accountCurrency: 'EUR'
marginRate: 0.0200
now I need to use the first four fields in each struct to fill the uitable and I don't know how to do it... Please can you help me?
Cheers
Francisco
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!