May 30, 2009

Some fun with matlab

I have not been able to do a lot of blogging on this site of late. Procrastination is the reason. Also, I was a bit busy with my project-work ( or the lack of it!!). Here I write about a small script i wrote to convert from mat files to csv files. I searched a lot for existing solutions but alas none was available though csv to mat converters exit in bulk.  While i wrote the script i realized the reason for non existance of such a script.
In Matlab you can store different types of information into a Mat file and some of it might not be easy to represent directly in a CSV file. for example structures cannot logically be put in a CSV file but arrays are easy to convert into csv.
So i wrote a script which can convert mat to csv but with a restriction. The MAT file should not contain any structures or row array's. It can have only column array's. Ofcourse, i know it is simple to change the column to row.

I dont think i can upload a file on to this blog, so till i can put the stuff on esnips this is the only way to share it.:-(


function mat2csv(fname,target)
% MAT2CSV convert a mat file to csv file
% MAT2CSV('matfilename.mat','csvfilename.csv')
% Output is generated using the data provided in the matfile ( one col per data element)
% Unused cells will be filled with zero's
% TODO: Currently the CSV file does not have column names, this will be
% added in next version
if(nargin<2)
    error 'Incorrect Number of inputs. Refer to usage by using "help mat2csv"'
end
y = open (fname);
largest_entry =0;
flds = fieldnames(y);
for idx=1:size(flds)
    eval ( strcat('if(size(y.',char(flds(idx)),',2)> largest_entry)largest_entry = size(y.',char(flds(idx)),',2); end'));
end
eval ('outmatrix = zeros(largest_entry,size(flds,1));');
for idx=1:size(flds)
    eval ( strcat('outmatrix(1:size(y.',   char(flds(idx)),  ',2),', int2str(idx) ,') = (y.', char(flds(idx)), ');')  );
end
fl ='';
for idx=1:size(flds)
    fl = strcat(fl,char(flds(idx)),',');
end
[rc,cc] = size(outmatrix);
fid=fopen(target,'wt');
fprintf(fid,'%s\n',fl);
for idx=1:rc
   for jdx=1:cc-1
        fprintf(fid,'%d,',outmatrix(idx,jdx));
    end
    fprintf(fid,'%d\n',outmatrix(idx,jdx+1));
end
fclose(fid);
end

Powered by ScribeFire.

May 20, 2009

Faster and Hotter chips!!

I have not been able to blog here due to two reasons. One I got lazy, two is first as the same. Any way now i have woken up from my slumber. This neat article talks about a new 8 core chip ( for servers) from Intel. However, have you ever wondered why suddenly there was a paradigm shift from having faster chips (3GHz or more) to having more cores?

The main reason ( though there might be many others) is the problem of heat dissipiation. Just to give a little bit more information in this regard i will try to go a bit below the layer. The modern chips are all based on CMOS technology. Though most magazines call them as transistors they are really MOSFET's ( which means MOS Feild Effect Transistors). CMOS has this wonderful property that it consumes literally no power when it is holding a logic 'O' or logic '1'. So why the power loss? The power loss really occurs when there is a switching of the CMOS from the logic '0' to logic '1' or visa versa.

This means that more you switch the transistor the more heat you dissipiate. The more heat you dissipate the more cooling need for your chip. Now we are left with two options, either ensure that  we cool the chip well or we reduce the heat generated. To a great extent we can cool the chip by adding bigger fans and heat sinks, however there is a limit to this ( because the heat generated takes a finite amount of time to get carried out and be dissipiated!!). If we concentrate on the second option we observe that if we do not switch the transistors so fast we can control the heating. This is what Intel has chosen to do by not trying to pump up the gigahertz. However, to boost performance now there are two cores ( which run at a slower rate!!) which can parallely execute instructions which are not directly dependent on each other . The story i am sure is more than this and i am not technically competant enough to put in that stuff here. However, someone i know does. I would be requesting him to add a few lines to this blog in a few days.
Please leave your comment if you have one. You can subscribe to this blog by using the links under "Subscribe" section.




Powered by ScribeFire.