[ANSWERED] Converting .txt file from an URL to a matrix

So i basicly have to extract information out of "http://asc.di.fct.unl.pt/ice/TP1/Aluminio.txt" and build a matrix with exact same lines and columns (679, 2) respectively.
I have this:
function [ output_args ] = processar( url )
DataFromUrl = urlread(url);
DataOnArray = strsplit(DataFromUrl);
DataOnArray = cell2mat(DataOnArray);
DataOnMatrix = vec2mat(DataOnArray, 2);
disp(DataOnArray)
end
cell2mat(DataOnArray) returns me a full string like this: 005354801035484.832E-051035487.596E-051035480.000096682071290.0....... and so on, concatenating everything basicly, instead of returning me a normal array with suppously (1358x1) of size, and therefore the vec2mat it's just gonna split the full string from 2 into 2 characters.
Any help/suggestions? Thanks

回答 (4 件)

Thorsten
Thorsten 2015 年 4 月 29 日

1 投票

D = urlread('http://asc.di.fct.unl.pt/ice/TP1/Aluminio.txt');
X = reshape(sscanf(D, '%f'), 2, [])';
KL
KL 2015 年 4 月 29 日

1 投票

urlwrite('http://asc.di.fct.unl.pt/ice/TP1/Aluminio.txt','urlcont.txt')
N = dlmread('urlcont.txt','\t');
Neil Caithness
Neil Caithness 2015 年 4 月 29 日
編集済み: Neil Caithness 2015 年 4 月 29 日

1 投票

textscan will do a nice job too with slightly different behaviour.
s = urlread('http://asc.di.fct.unl.pt/ice/TP1/Aluminio.txt');
x = textscan(s,'%f %f')
x =
[679x1 double] [679x1 double]
Peter Peter
Peter Peter 2015 年 4 月 29 日

0 投票

thx alot guys, it works now

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2015 年 4 月 29 日

編集済み:

2015 年 4 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by