Issues when reading a .nc file - matlab

I got this .nc file. However, when I read the file like this
ncid = netcdf.open(ncfile)
It gives me only a number. It was supposed to contain some data. I am not sure what's wrong with it. Can anyone please provide some information?

According to the documentation, netcdf.open only returns the NetCDF ID, not the data:
ncid = netcdf.open(source) opens source, which can be the name of a
NetCDF file or the URL of an OPeNDAP NetCDF data source, for read-only
access. Returns a NetCDF ID in ncid.
You probably want to use ncread.

Note:
ncid = netcdf.open(ncfile)
Where ncid is a netCDF file identifier returned by netcdf.create or
netcdf.open.
Eg : In your Case
ncid=netcdf.open(ncfile,'NC_NOWRITE');
varidp=netcdf.inqVarID(ncid,'varname'); //returns varid
Eg : Official
This example opens the example netCDF file included with MATLABĀ®, example.nc, and uses several inquiry functions to get the ID of the first variable.
ncid = netcdf.open('example.nc','NC_NOWRITE');
% Get information about first variable in the file.
[varname, xtype, dimids, atts] = netcdf.inqVar(ncid,0);
% Get variable ID of the first variable, given its name
varid = netcdf.inqVarID(ncid,varname)
Ref:http://www.mathworks.in/help/matlab/ref/netcdf.inqvarid.html
Thanks

Related

CSV data from URL to table

How can I convert CSV file to a proper table that has rows and columns, reading the CSV directly from a URL?
clc;
clear all;
S = {urlread('https://people.sc.fsu.edu/~jburkardt/data/csv/homes.csv')}
T = array2table(S)
You can use webread:
data = webread( 'https://people.sc.fsu.edu/~jburkardt/data/csv/homes.csv' );
This gives you a table variable:
In the documentation you can see several choices for the 'ContentType' option. The default 'auto' will work in this case, and be identified as a table due to the .csv file extension. If you wanted to be over-specific, you could also specify the 'table' content type as part of the optional web options input to webread.
I would suggest you to download the file. And then with readtable("examples.csv"), it works with your data:
filename = 'C:\temp\homes.csv';
data = readtable(filename);

Using Scispark can we know all the variables included in a netcdf file ?

val data = sc.NetcdfDFSFile("/home/akhilav/Downloads/120mb.nc",variable,3)
here i give variable as latitude. beacause I know the variables.If we r not familiar with variables how can we extract from netcdf file through code.
Import org.dia.loaders.NetCDFReader
...
netcdfPath = "--**PATH TO A NETCDF FILE**--"
varNames = NetCDFReader.loadNetCDFVar(netcdfPath)
The only caveat here is that the netcdfPath string needs to be a local path not an HDFS path. loadNetCDFVar() opens a netcdffile, extracts all its variables, and returns it as a list of strings. You can then pass that list when calling the NetcdfDFSFile() function.

how to read text files from content repository

My requirement is read text files from content repository in sap abap.I used SCMS_DOC_READ FM to read image file and creating url DP_CREATE_URL for creating image url but SCMS_DOC_READ not working for text.
Can any one suggest some code, FM or class .
There are two options based on your requirement:
Option 1: Use READ DATASET to read file.
DATA : FNAME(60) type c VALUE 'myfile.txt',
TEXT2(5) type c.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE.
DO.
READ DATASET FNAME INTO TEXT2 LENGTH LENG.
WRITE: / SY-SUBRC, TEXT2.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET FNAME.
Option 2: Use Class CL_ABAP_CONV_IN_CE to read file.
Refer this tutorial page to get more information on this class.
You can easily find the answer there: http://scn.sap.com/thread/525075
If you want the short answer, you should use this(Note: I am not the author of this part):
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = "File path"
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT.
Note : Internal table structure should be same as text File.

Save and load fft to .mat file

I have an FFT and I want to save this to .mat file and then read it from that .mat file. I want to use my loaded data for a division. Here is my code
save ('file_fft','a_fft');
b = load ('file_fft');
c = abs (d_fft) ./ abs (b);
In my command window I see that
b = file_fft [4000 * 1 double].
And then I get error message
'Undefined function 'abs' for input arguments of type 'struct''
I tried after deleting abs. I got this error
'Undefined function 'rdivide' for input arguments of type 'struct''
Does anybody have any idea that why it is not working and how i can solve it?
Check the documentation for the load function:
S = load(___) loads data into S, using any of the input arguments in
the previous syntax group.
If filename is a MAT-file, then S is a structure array.
If filename is an ASCII file, then S is a double-precision array
containing data from the file.
So b is a structure and as suggested in the comment, you need to access the data as abs(b.a_fft).
The problem is that load() already creates the file structure that is inside the .mat file. When you assign file_fft with load, it creates a struct.
From the documentation of load():
S = load(_) loads data into S, using any of the input arguments in
the previous syntax group.
If filename is a MAT-file, then S is a structure array.
Edit:
I got sniped :-P
Here's another working example of code:
save ('file_fft','a_fft');
load ('file_fft');
c = abs (d_fft) ./ abs (file_fft);

extracting data from within xml files using MATLAB

I am a complete programming beginner trying to learn MATLAB. I want to extract numerical data from a bunch of different xml files. The numerical data items are bounded by the tags and . How do I write a program in MATLAB?
My algorithm:
1. Open the folder
2. Look into each of 50 xml files, one at a time
3. Where the tag <HNB.1></HNB.1> exists, copy numerical contents between said tag and write results into a new file
4. The new file name given for step 3 should be the same as the initial file name read in Step 2, being appended with "_data extracted"
example:
FileName = Stewart.xml
Contents = blah blah blah <HNB.1>2</HNB.1> blah blah
NewFileName = Stewart_data extracted.txt
Contents = 2
The fundamental function in MATLAB to read xml data is xmlread; but if you're a complete beginner, it can be tricky to work with just that. Try this series of blog postings that show you how to put it all together.
Suppose you want to read this file:
<PositiveSamples numImages="14">
<image numSubRegions="2" filename="TestingScene.jpg">
<subregion yStart="213" yEnd="683" xStart="1" xEnd="236"/>
<subregion yStart="196" yEnd="518" xStart="65" xEnd="226"/>
</image>
</PositiveSamples>
Then in matlab, read the file contents as follows:
%read xml file
xmlDoc = xmlread('PositiveSamples.xml');
%Get root element
root = xmlDoc.getDocumentElement();
%Read attributevale
numOfImages = root.getAttribute('numImages');
numOfImages = char(numOfImages);
numOfImages = uint16(eval(numOfImages));