Extract data from one array to another based on a string matching in Column 1
조회 수: 1 (최근 30일)
이전 댓글 표시
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' }
{'12:58:35.557713'}
{[ 11.7094]}
C(:,:,2) =
{'AAPL' }
{'12:58:35.412995'}
{[ 122.0862]}
C(:,:,3) =
{'ACB' }
{'12:59:16.777876'}
{[ 11.7097]}
etc...
C(:,:,12) =
{'AAPL' }
{'12:59:24.604849'}
{[ 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.
Thanks
Allan (working on learning matlab during lockdown)
댓글 수: 2
Anmol Dhiman
2020년 12월 7일
Hi Allan,
"The data is collected for all the stocks in one array". Can you give the description of the array or share the data files so as to provide the resolution.
Regards,
Anmol Dhiman
답변 (1개)
Anmol Dhiman
2020년 12월 9일
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);
Hope it helps
Regards,
Anmol Dhiman
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!