Display data from an online file

2 次查看(过去 30 天)
Hi, I'm trying to have text appear on the screen that displays the information found in this online document, but I only get the first two to display correctly. The message that appears says this:
DATE: 11100107-LOC-1804-COORDS-N-MAGTYPE
and I would like it to say:
DATE: 11100107-LOC-1804-COORDS-N28E62-MAGTYPE-B
Because this is the first line of the file: 11100107 1804 N28E62 B
Code:
block = urlread('ftp://ftp.ngdc.noaa.gov/STP/SOLAR_DATA/SUNSPOT_REGIONS/USAF_MWL/2010/USAF.10');
readData = textscan(block, '%d %d %c %6c', 'delimiter', char(' '));
date = readData{1};
loc = readData{2};
coords = readData{3};
type = readData{4};
formatSpec = 'DATE-%d-LOC-%d-COORDS-%c-MAGTYPE-%c';
hPopSunspots = uicontrol(hPanelAni,'Style','text','Units','normalized','FontSize',14,...
'Position',[1.72 -0.55 2.60 0.12],'String',sprintf(formatSpec,date,loc,coords));
clear readData
I would like to be able to display the next row for each new object but I'll settle for one. Any ideas? Thanks a lot!

采纳的回答

per isakson
per isakson 2012-5-1
It is easier to handle the first four columns as text. readData is cell array of cell arrays. Delimiter takes care of the spaces. "%*[^\n]" takes care of "rest of line".
readData = textscan(block, '%s%s%s%s%*[^\n]', 'delimiter', char(' '));
....
formatSpec = 'DATE-%s-LOC-%s-COORDS-%s-MAGTYPE-%s';
....
..... sprintf(formatSpec,date{:},loc{:},coords{:})
--- EDIT ---
Make changes in the indexing of the following lines. That will give you column vectors containing data from all rows.
date = readData{:,1};
loc = readData{:,2};
coords = readData{:,3};
You need to learn how to use the debugger and inspect variables in debug mode. (Matlab shows the "K>>" prompt in the command window.) There are good videos on debugging in the Matlab help.
  1 个评论
Daimien Burks
Daimien Burks 2012-5-1
Thanks per! Can you now tell me how to get to the next line, as if I'm placing this data call in a loop?
for (n=# of rows)
....%read data from the first 4 columns of 1 row
....sprintf(data)
....%skip to the next row
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by