How to enter a numeric matrix published on the web page https://es​c113.blogs​pot.com/20​22/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
A = 20×10
0.7630 1.0383 0.5844 1.3693 0.7399 0.8377 1.4421 1.1491 0.8685 1.0085 1.1541 1.4961 0.8998 1.0797 0.6233 1.4001 1.4561 1.2317 1.1256 1.0108 1.1892 0.5782 0.7599 1.0499 0.6839 0.8692 1.0752 1.1477 1.2802 1.3176 1.2482 0.9427 1.3001 0.6450 0.7400 0.6112 0.5598 0.9509 0.5811 1.2948 0.9505 0.6067 0.9314 1.3530 0.9173 1.2803 0.7348 1.0470 1.4294 1.1443 0.5838 1.4619 1.4106 1.1221 0.5497 0.8897 0.8532 0.7963 1.2757 0.8786 0.7290 0.5046 0.6818 0.8510 1.4027 0.7417 1.3212 1.2447 0.9868 1.3116 1.4133 1.2749 0.7638 1.0132 1.4448 0.9039 0.5154 0.6890 0.9359 1.0328 0.6524 1.3173 0.6455 0.9018 0.9909 0.5965 0.5430 1.1868 0.9468 0.8507 1.3258 1.3687 0.6361 0.5760 0.9893 0.6320 0.6690 0.6835 0.8063 1.4390
But I think my solution is to mach complicated and not universal.
Can somebody show me shorter solution?
Thank you.

回答(1 个)

Sarthak
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.

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by