Extract data from one array to another based on a string matching in Column 1

1 view (last 30 days)
I have this a program that collects the 'symbol', 'time' and 'VWAP' (which is a price, every thiry seconds. The data is collected for all the stocks in one array.
I am trying to get the data out for just one stock in the list and create a new array. I have tried ismember, sort, indexing and am getting errors on the string field for 'symbol'.
VWAP = []
TheList = {'ACB','AAPL'}
new_VWAPdata =[] % 1 run once
TheList = {'ACB','AAPL'}
% this data is rerun every 30 seconds to get the latest prices.
dataV = IQML('quotes', 'Symbol', TheList, 'Fields','Most Recent Trade Time,VWAP');
new_VWAPdata = [new_VWAPdata , dataV]
j = new_VWAPdata % renamed the array for ease of use in testing
I tried to sort the data and take out one symbol but got an error:
ind1 = j(:,1) == 'AAPL';
Operator '==' is not supported for operands of type 'struct'.
So I then converter the struct to an array:
C = struct2cell(j)
3×1×12 cell array
C(:,:,1) =
{'ACB' }
{[ 11.7094]}
C(:,:,2) =
{'AAPL' }
{[ 122.0862]}
C(:,:,3) =
{'ACB' }
{[ 11.7097]}
C(:,:,12) =
{'AAPL' }
{[ 122.0863]}
The I tried to get the data again from the new array and I get another error.
>> ind1 = C(:,1) == 'AAPL';
Operator '==' is not supported for operands of type 'cell'.
I have no idea where to go from here.
How do I create a new array with each variable on the arrays 'TheList' as a new array? Or extract the data for just 'AAPL' include Time and VWAP to a new array?
I've been stuck on this for hours.
Allan (working on learning matlab during lockdown)
Allan Munro
Allan Munro on 7 Dec 2020
Hi Anmol, here is the data I get from the array. I am trying to get the data out just for one symbol.

Sign in to comment.

Answers (1)

Anmol Dhiman
Anmol Dhiman on 9 Dec 2020
Hi Allan,
It will be better if you convert your data into table with help of below command
T = struct2table(s); % convert the struct array to a table
sortedT = sortrows(T, 'Symbol'); % sort the table by 'Symbol'
sortedS = table2struct(sortedT);
You can also go through Table Operations in MATLAB in case you want to do more.
Hope it helps
Anmol Dhiman




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by