Cant get headerlines to work

조회 수: 3 (최근 30일)
Cio
Cio 2014년 10월 21일
댓글: Star Strider 2014년 10월 21일
Hi guys, I've recently bought Matlab and i dont know a great deal so bear with me. So i want to input data into matlab from
'http://jsoc.stanford.edu/SUM20/D358012442/S00000/Uy/1909:105.0_00.0W00.0N.Uy'
i use
urlread('http://jsoc.stanford.edu/SUM20/D358012442/S00000/Uy/1909:105.0_00.0W00.0N.Uy')
which gives me the data i need but i cant get it to ignore the first 7 lines of text.
I have been trying by textread('ans','headerlines', 7) which doesnt work.
If i select the data manually after putting in the urlread, and putting [..] around the data i want, it does give me what i want which comes up as '31x9 double' in workspace, instead of '1x2881 char'.
Can i get the data to be plotted in '31x9 double' directly from the website without me copy and pasting it, theres a lot of data so im looking for the shortest way. My explanation is terrible, i hope someone gets it, Any help is appreciated. Thanks in advance.

채택된 답변

Star Strider
Star Strider 2014년 10월 21일
Use urlwrite instead.
This works:
File = urlwrite('http://jsoc.stanford.edu/SUM20/D358012442/S00000/Uy/1909:105.0_00.0W00.0N.Uy','Stanford_Data.txt');
fidi = fopen(File);
D = textscan(fidi, repmat('%f',1,9), 'Delimiter','\n', 'HeaderLines',7);
Dd = cell2mat(D);
  댓글 수: 2
Cio
Cio 2014년 10월 21일
thank you, that did work, you are a scholar and a gentleman
Star Strider
Star Strider 2014년 10월 21일
My pleasure!
I do my best to be both!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2014년 10월 21일
Cio - as you noted, the result of the urlread is a 1x2881 character array. To convert it to a matrix, you could just look for all occurrences within the string of the new line feed character whose ASCII decimal value is 10. You could then split all strings on this "delimiter" and get the 31x9 matrix as
resultStrAsArray = ...
urlread('http://jsoc.stanford.edu/SUM20/D358012442/S00000/Uy/1909:105.0_00.0W00.0N.Uy');
resultAsMatrix = char(strsplit(resultStrAsArray,char(10))');
% now remove the first seven rows
resultAsMatrix = resultAsMatrix(8:end,:);
Try the above and see what happens! Note that it may not work in all cases due to the assumption that the new line feed character (10) can be used to break the string array into multiple strings.
  댓글 수: 1
Cio
Cio 2014년 10월 21일
that did not come up right, and i have no idea why but i did find a solution, I thank you for your kindness

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by