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) 

Please follow and like us:

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.


Question:

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.

Answer:

load hourlyperiod.mat
d = hourlyperiod ;
fid = fopen('iwant.dat','w') ;
for i = 1:length(d)
 fprintf(fid,'%s \n',d(i,:)) ;
end
fclose(fid) ;
Please follow and like us:

Split excel worksheets to individual files

If we have about many sheets in excel, and save all the sheets as their own files will definitely was not about to do this by hand. it take a take time!. I found a good tips from the internet, to solve this problem,in which using the macro!.

Here the code:

Sub CreateNewWBS()
 Dim wbThis As Workbook
 Dim wbNew As Workbook
 Dim ws As Worksheet
 Dim strFilename As String
 Set wbThis = ThisWorkbook
 For Each ws In wbThis.Worksheets
 strFilename = wbThis.Path & "/" & ws.Name
 ws.Copy
 Set wbNew = ActiveWorkbook
 wbNew.SaveAs strFilename
 wbNew.Close
 Next ws
End Sub

References/Sources:

http://superuser.com/questions/561923/how-can-one-split-an-excel-xlsx-file-that-contains-multiple-sheets-into-sep

Excel – save worksheets as separate files

References/Sources:

Please follow and like us:

Remove the last part of every line in notepad++

If we have the lines:

http://lunar.earth.northwestern.edu/mediawiki/index.php/Limitless_It_the_film_high_quality
http://sportnaslava.info/wiki/index.php?title=User:CisBlakeman861

and we want final lines become like this:

http://lunar.earth.northwestern.edu/mediawiki/index.php
http://sportnaslava.info/wiki/index.php

we can applied notepad++ to do it. The solution as follow:

1) Using notepad++ and go to the search. Please used the regular expression as search mode

2) search

index\.php.*$

index\ means search for word; .* means everything else; $ means the end of line.

3) then replace with

index.php

4) That should find everything after (and including) index.php, and replace it with just index.php.

http://lunar.earth.northwestern.edu/mediawiki/index.php
http://sportnaslava.info/wiki/index.php

References: http://superuser.com/questions/391318/how-do-i-remove-the-last-part-of-every-line-in-notepad

Please follow and like us:

(Repost) Batch Change/Rename File Extensions In Windows

A good tips from http://www.addictivetips.com/windows-tips/batch-change-rename-file-extensions-in-windows/. Please refer to the original article.

————————————————————————–

Batch Change/Rename File Extensions In Windows

Do you want to batch rename file extensions in one simple step? Changing each file extension separately can be a pain in some cases where you have to change extensions of more than 100 files.

One of method using command line. The method as follow:

  • Select the folder which has all the files who’s extension you would like to change. As an example I have made a folder named “test”, inside this folder I have placed four images in .jpg format. To change the extension of the files inside the folder, press Shift and right-click on the folder and select Open Command Window Here.

open command window

  • You will now see a Command Window with the current folderdirectory open. Now type the following command line,
ren *.(current extension name) *.(extension you want)
  • Since I want to change the extension from .jpg to .jpg, in my case the command line would be,
ren *.jpg *.jpg

change extension

  • Now all the files inside the folder will change to the extension you want. It’s that simple.
Please follow and like us:

Grouping boxplot in matlab

Here an example from http://stackoverflow.com/questions/16267440/grouping-boxplot-matlab. The example is about on how to create a boxplot for multiple group of variables. The example as follows:

x=rand(1000,6); %variable x
y=rand(1000,6); %variable y
D(:,1:2:12)=x; %rearrange x into d.
D(:,2:2:12)=y; %rearrange y into d

% first column of D, will fill with column of x, then second... 
% column of D will fill with 1st column of y. then the sequent... 
% will follow.

and

figure('color',[1,1,1]); %create a blank graph
boxplot(D,'factorgap',10,'color','rk') %make a box plot on those blank graph
axis([0 25 -1 5]) %not compulsory:rearrange back axis 

set(gca,'xtick',1.8:4.3:50) %put xtick to x-axis
set(gca,'ytick',0:10) %put tick to y-axis
set(gca,'xticklabel',{'Direct care','Housekeeping','Mealtimes','Medication','Miscellaneous','Personal care'}) %label to each x-axis

ylabel('Normalised Y');
 legend(findobj(gca,'Tag','Box'),'HBN04-01 multibed','YAB single ') %put legend to figure
Please follow and like us:

Run for 100 times (loops) and save each result of run into a single matrix in MATLAB

Here a simple example: You want to run 100x times of this function, y=2i, where i is integer values (0 until 100) and you want to save each y into a single matrix (named as y1), you can write as follow:

for i=1:100 % 100 times of loops 
y=2*i % our function
y1(i,:)=y % each y will save on a single column in the matrix end
end
Please follow and like us: