Putting data into tables and looping over it

1 次查看(过去 30 天)
Hi guys,
I am trying to run over a set of structured headlines and detect the issuer written in the headline.
I managed to write a code that will detect the issuer using a dictionary, I just need a little help on putting the data together systematically and looping over it efficiently.
Here's the code:
Import text to match an issuer to
document1 = "Analyst Actions: Citigroup Cuts Fiverr International's Price Target to $22 From $31, Reiterates Neutral Rating"
document2 = "Analyst Actions: JPMorgan Downgrades Beyond Meat to Neutral From Overweight, Cuts Price Target to $134 From $138"
document3 = "Analyst Actions: Credit Suisse Raises Beyond Meat's Price Target to $125 From $115; Keeps Neutral Rating"
document4 = "Analyst Actions: Oppenheimer Initiates Coverage on Beyond Meat With Perform Rating"
document5 = "Analyst Actions: Morgan Stanley Trims GoPro's Price Target to $3.50 From $4.50, Maintains Underweight Rating"
document6 = "GoPro downgraded by Zacks Investment Research to strong sell. $3.75 PT. (NASDAQ:GPRO)"
data = table(document1,document2,document3,document4,document5,document6)
data(:,2) % reference the 2nd column of data
data{:,2} % takes the content of the 2nd column of data
List of issuers
issuer = ["JPMorgan";
"Citigroup";
"Credit Suisse";
"Oppenheimer";
"Morgan Stanley";
"Zacks";
"UBS"]
Loop to find the issuer
for i = 1:size(issuer)
if (contains(document6,issuer(i)))
x = issuer(i)
else
nomatch = "No match."
end
end
I basically would want to put the data in a table and instead of document6 in the loop replace it with the corresponding document (headline) to scan.
In the end I need to collect the write answers (x) and put it next to the original headline as final data.
Would appreciate your help.
Thank you!

回答(1 个)

kgrunden
kgrunden 2020-11-4
If the table is reoriented to have the documents in a single row, instead each in a column, it possible to iterate the table and place the answer another column.
doc = {document1, document2, document3, document4, document5, document6}';
data = table(doc);
for j = 1:size(doc)
for i = 1:size(issuer)
if (contains(doc{j}, issuer(i)))
issuerCol(j) = issuer(i);
break;
else
issuerCol(j) = "No match.";
end
end
end
data.issuer = issuerCol'
Executing the code then gives:
data =
6×2 table
doc issuer
______________________________________________________________________________________________________________________ ________________
{["Analyst Actions: Citigroup Cuts Fiverr International's Price Target to $22 From $31, Reiterates Neutral Rating" ]} "Citigroup"
{["Analyst Actions: JPMorgan Downgrades Beyond Meat to Neutral From Overweight, Cuts Price Target to $134 From $138"]} "JPMorgan"
{["Analyst Actions: Credit Suisse Raises Beyond Meat's Price Target to $125 From $115; Keeps Neutral Rating" ]} "Credit Suisse"
{["Analyst Actions: Oppenheimer Initiates Coverage on Beyond Meat With Perform Rating" ]} "Oppenheimer"
{["Analyst Actions: Morgan Stanley Trims GoPro's Price Target to $3.50 From $4.50, Maintains Underweight Rating" ]} "Morgan Stanley"
{["GoPro downgraded by Zacks Investment Research to strong sell. $3.75 PT. (NASDAQ:GPRO)" ]} "Zacks"
>> data{3,:}
ans =
1×2 string array
"Analyst Actions: Credit Suisse Raises Beyond Meat's Price Tar?" "Credit Suisse"

类别

Help CenterFile Exchange 中查找有关 Testing Frameworks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by