How to enter a numeric matrix published on the web page https://esc113.blogspot.com/2022/11/data.html
1 view (last 30 days)
Show older comments
I found how to enter a number matrix posted on the web page https://esc113.blogspot.com/2022/11/data.html.
See my code:
url = 'https://esc113.blogspot.com/2022/11/data.html';
a= webread(url);
b= extractHTMLText(a);
fID=fopen("abc.txt",'wt');
fprintf(fID,"%s",b);
fclose(fID);
fID=fopen("abc.txt",'rt');
tline = fgets(fID);
tline = fgets(fID);
tline = fgets(fID);
tline = fgets(fID);
for i=1:20
tline = fgets(fID);
A(i,:)=sscanf(tline,'%g');
end
A
But I think my solution is to mach complicated and not universal.
Can somebody show me shorter solution?
Thank you.
0 Comments
Answers (1)
Sarthak
on 20 Mar 2023
Hi Vasiliy,
MATLAB offers inbuilt functions for text parsing and extractions. You can find elements from the html tree of your webpage.
url = 'https://esc113.blogspot.com/2022/11/data.html';
a= webread(url);
% Generate HTML tree
tree = htmlTree(a)
% Find required element using css selectors
element = findElement(tree, '.post-body');
% Extract text from the element
str = extractHTMLText(element);
You can also refer to the following documentation.
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!