필터 지우기
필터 지우기

Display data from an online file

조회 수: 2 (최근 30일)
Daimien Burks
Daimien Burks 2012년 5월 1일
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