How to enter a numeric matrix published on the web page https://esc113.blogspot.com/2022/11/data.html
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sarthak
2023-3-20
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!