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!
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!