Borrar filtros
Borrar filtros

Display data from an online file

2 visualizaciones (últimos 30 días)
Daimien Burks
Daimien Burks el 1 de Mayo de 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!

Respuesta aceptada

per isakson
per isakson el 1 de Mayo de 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 comentario
Daimien Burks
Daimien Burks el 1 de Mayo de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by