Filter löschen
Filter löschen

Display data from an online file

2 Ansichten (letzte 30 Tage)
Daimien Burks
Daimien Burks am 1 Mai 2012
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!

Akzeptierte Antwort

per isakson
per isakson am 1 Mai 2012
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 Kommentar
Daimien Burks
Daimien Burks am 1 Mai 2012
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by