Normalize values in a matrix to be between 0 and 1 (Matlab Tips)

I’m run a function in Matlab and it requires a matrix of variables within 0 and 1. The way to normalize the values to be between 0 and 1, and transform back to the original matrix as follows:

b = [10; 0; 1; 1];

%% normalized matrix B to 0 and 1
normB = b - min(b(:));
normB = normB ./ max(normB(:))

%% transform normalized matrix B to the original matrix
B_sim = normB_sim .* max(b(:))

Make sure, when transforming normalized matrix to the original matrix, you provided the maximum value of the original matrix. It not, the code cannot be run.

Original source: (Link) 

Posted in Code | Tagged , | Leave a comment

Multiple colors to features within a single shapefile

I have received one shape file from a friend, who has a lot of features and attributes. However, it is within a single shapefile. So, it is difficult to me to recognise their features, since QGIS is only displayed one colour.

There is actually a way to display multiple colours of features although you have a single shape file. You can change the styles of the shape file in the layer properties. Double click the layer and select style. Select Categorized style and choose a field you want to visualize. Remember to classify your values before leaving the dialogue.


Posted in Geoinformatics | Tagged | Leave a comment

Soil & Water Assessment Model (SWAT) in QGIS

It is a good news that SWAT can be run in QGIS. This integration is known as QSWAT and can be download from the official website of SWAT (

I include a good tutorial that I found on the internet for the reference.

Posted in Geoinformatics, Hydraulics | Tagged , , , | Leave a comment

Import “starred places” into a My Map

There is a situation, you have saved several places in Google Maps and you want to display all those places in one map in Google Maps. How to do it? It is a way to do it, by using My Maps. However, there is no way to add them through My Maps directly. Here the tips from this link to do it:

  1. Export them using Google Takeout
  2. Export them from “Google Maps (My Places)”, not from “Bookmarks”. They will be downloaded as a GeoJSON file.
  3. Use this site to convert the file to KML GeoJSON
  4. Once download the KML file, can import it into the custom map.
Posted in Geoinformatics | Tagged , , | Leave a comment

Using HEC-GeoRAS for the HEC-RAS modelling (Videos Expired!)

Note: All video tutorials have been expired!. I will make the videos to replaced expired videos soon. Sorry for the inconvenience caused. – zulkarnain

If you do HEC-RAS for the flood or water quality modeling, HEC-GeoRAS may help you. In general, HEC-GeoRAS is a plugin in ArcGIS, to help to process geospatial data from the raster image. 1) It is very helpful that allows the preparation of geometric data for import into HEC-RAS and 2) helps to display the GIS outcome, based on the outcome of HEC-RAS. This software can be download from this link.

Preparation of geometric data for import into HEC-RAS

To create the import file, the user must have an existing digital terrain model (DTM) of the river system in the ArcInfo TIN format. The user creates a series of line themes pertinent to developing geometric data for HEC-RAS. The themes created are the Stream Centerline, Flow Path Centerlines (optional), Main Channel Banks (optional), and Cross Section Cut Lines referred to as the RAS Themes.

These are the best tutorial that I obtained from youtube:

Part 1

Part 2

Part 3

Part 4

Helps to display the GIS outcome

Water surface profile data and velocity data exported from HEC-RAS simulations may be processed by HEC-GeoRAS for GIS analysis for floodplain mapping, flood damage computations, ecosystem restoration, and flood warning response and preparedness.

The tutorial to export the data from HEC-RAS to GeoRAS as follows:

Credit: Yasir A. for the good tutorials.

Posted in Geoinformatics | Tagged , , | Leave a comment

Field Calculator in QGIS

In QGIS, if you want to calculate the real geometries (such as area, parameter, length etc.) of polygon/point based on the current coordinate system, we need using the field calculator.  If we use this calculator, we able to show the geometries in the features table. I list a few field calculators that may interest the QGIS user as follows:

latitude and longitude

$x or $y as a variable to get the x and y

Posted in Geoinformatics | Tagged , | Leave a comment

How to export string with timeperiod to .dat file? (Re-Post)

Here a question (original link) that I ask at Matlab Community that the reader may found useful.


I have a large string that containing time period such as 23-May-2009 02:00:00 (as attached). Variable editor in Matlab is unable to display these variables, since the variables have more that 524288 elements. I want to export the variables to .dat file, so I can see the list of the variables. I try to use fopen and fprintf functions to export the variables, but unsuccessful. Any help? Thank you.


load hourlyperiod.mat
d = hourlyperiod ;
fid = fopen('iwant.dat','w') ;
for i = 1:length(d)
 fprintf(fid,'%s \n',d(i,:)) ;
fclose(fid) ;
Posted in Code | Tagged , | Leave a comment

Menukar sistem koordinat menggunakan ArcGIS

Bila dapat shp files dari client dalam sistem koordinat kertau, mesti pening kepala. Mananya tidak, saya adalah pengguna QGIS dan function “on the fly” CRS transformation dalam QGIS sangat tidak membantu, berbanding function yang sama dalam ArcGIS. That why, ArcGIS sangat disukai oleh ramai orang sebab lebih muda berbanding QGIS. Tetapi, since ArcGIS perlu dibeli dan license sangat mahal, ini menyebabkan saya lebih suka menggunakan QGIS.

Berbalik kepada masalah saya, saya perlu ubah sistem koordinate kertau kepada WSG84, since default sistem QGIS adalah WSG84. Tambahan, kalau import files dari Google Earth, WSG84 akan digunakan. Dengan basic knowledge dlm QGIS dan ArcGIS yang sangat shallow, google lah cikgu saya. Saya terjumpa satu link orang Melayu yang ajar step by step macam mana hendak tukar. Saya repost balik post dia disini untuk rujukan saya dan pembaca disini.

Post beliau seperti berikut:

Di sini saya akan tunjukkan cara-cara menukar sistem koordinat tu menggunakan ArcMap. Contoh yang akan saya berikan ialah menukar data dari RSO ke WGS84.

1. Pastikan sistem koordinat sumber data

Mula-mula anda perlu pastikan apakah sistem koordinat yang digunakan oleh data yang ingin anda tukarkan sistem koordinat tu. Contohnya katalah saya ingin menukar data mukim saya ke WGS84. Saya perlu pastikan apakah sistem koordinat yg digunakan oleh mukim tu. Katakan saya tahu data mukim tu adalah data RSO,.. saya perlu pastikan pada ruangan XY Coordinate data tu tertera Kertau_RSO_Malaya_Meters dan bukannya Unknown.

Sekiranya nilai yang dipapar adalah Unknown, anda perlu define dahulu sistem koordinat pada data tu sebelum proceed langkah seterusnya. Contoh, kalau data mukim saya tu adalah data RSO, saya perlu define dahulu data tu sebagai RSO. Proses ni anda perlu buat dalam ArcCatalog ataupun Catalog Window.

Klik butang Select.. untuk define sistem koordinat sumber data
2. Set sistem koordinat untuk Data Frame.

Kemudian setkan sistem koordinat Data Frame mengikut sistem koordinat apa yang anda hendak convert. Macam contoh saya ni, saya nak convert mukim tu dari RSO ke WGS84, jadi sistem koordinat Data Frame tu saya perlu set dahulu sebagai WGS84.

3. Pastikan adakah terdapat perbezaan datum antara sistem koordinat.

Step ni agak penting juga untuk pastikan ketepatan data yang akan anda hasilkan nanti. Anda perlu tahu apakah datum yang digunakan antara sistem koordinat yang terlibat. Contohnya data mukim saya adalah RSO. RSO untuk Semenanjung menggunakan datum Kertau. WGS84 pula menggunakan datum WGS84…. bermaksud kedua-dua sistem koordinat menggunakan datum yang berbeza.

Sekiranya terdapat perbezaan datum, proses Datum Transformation perlu dilakukan. Mudah saja, klik saja butang Transformation pada dialog Data Frame Properties dan setkan transformation seperti gambar kat bawah ni.

4. Export data menjadi layer baru.

Kemudian export saja sumber data tu menjadi layer baru. Tapi jangan lupa, pastikan anda pilih option Use the same coordinate system as : the data frame. Kalau tak pilih option tu, nanti data yang dihasilkan tetap tak berubah, masih lagi sistem koordinat yang asal. Dalam contoh di bawah ni, data mukim tu saya convert menjadi shapefile dan saya namakan sebagai MukimWGS.shp.

OK …selesai sudah proses. Data mukim saya telahpun diconvert daripada RSO menjadi WGS. Secara ringkasnya, anda bolehlah rujuk gambarajah bawah ni untuk step-step yang telah saya huraikan tadi.

Posted in Geoinformatics | Tagged , | Leave a comment

Protected: Hydrology and Hydraulics Software

This content is password protected. To view it please enter your password below:

Posted in Geoinformatics, Hydraulics, Hydrology | Tagged , | Enter your password to view comments.

Example of Bootstrapping

In a statistical analysis, bootstrapping is a popular technique, especially useful when the sample size is small. It is involved with resampling and the technique is assume nothing about the distribution of our data. It is noted that a small sample (<40), we can assuming a normal or a t-distributions.

Bootstrapping can be run in many statistical software in the market. For me, I like to use SPSS, since the software has integrating bootstrapping in each analysis. Many codes that implementing bootstrapping can be found in Matlab and R-language.

The following example is how this technique works that been obtained from this source:

Example Sample

We begin with a statistical sample from a population that we know nothing about. Our goal will be a 90% confidence interval about the mean of the sample. Although other statistical techniques used to determine confidence intervals assume that we know the mean or standard deviation of our population, bootstrapping does not require anything other than the sample.

For purposes of our example, we will assume that the sample is 1, 2, 4, 4, 10.

Example – Bootstrap Sample

We now resample with replacement from our sample to form what are known as bootstrap samples. Each bootstrap sample will have a size of five, just like our original sample. Since we randomly selecting and then are replacing each value, the bootstrap samples may be different from the original sample and from each other.

For examples that we would run into in the real world we would do this resampling hundreds if not thousands of times. In what follows below, we will see an example of 20 bootstrap samples:

2, 1, 10, 4, 2
 4, 10, 10, 2, 4
 1, 4, 1, 4, 4
 4, 1, 1, 4, 10
 4, 4, 1, 4, 2
 4, 10, 10, 10, 4
 2, 4, 4, 2, 1
 2, 4, 1, 10, 4
 1, 10, 2, 10, 10
 4, 1, 10, 1, 10
 4, 4, 4, 4, 1
 1, 2, 4, 4, 2
 4, 4, 10, 10, 2
 4, 2, 1, 4, 4
 4, 4, 4, 4, 4
 4, 2, 4, 1, 1
 4, 4, 4, 2, 4
 10, 4, 1, 4, 4
 4, 2, 1, 1, 2
 10, 2, 2, 1, 1

Example – Mean

Since we are using bootstrapping to calculate a confidence interval about the population mean, we now calculate the means of each of our bootstrap samples. These means, arranged in ascending order are: 2, 2.4, 2.6, 2.6, 2.8, 3, 3, 3.2, 3.4, 3.6, 3.8, 4, 4, 4.2, 4.6, 5.2, 6, 6, 6.6, 7.6.

Example – Confidence Interval

We now obtain from our list of bootstrap sample means a confidence interval. Since we want a 90% confidence interval, we use the 95th and 5th percentiles as the endpoints of the intervals. The reason for this is that we split 100% - 90% = 10% in half so that we will have the middle 90% of all of the bootstrap sample means.

For our example above we have a confidence interval of 2.4 to 6.6.
Posted in Mathematics | Tagged , | Leave a comment