Friday 28 March 2014

How to go to a particular byte in a file in Matlab?

1. Use fseek

2. Note: 
a. In file, byte numbering starts from 0. Therefore, if we want to go to Nth byte, then we have to move the pointer by (N-1) bytes.

fseek(fid, N-1,'bof'); %skips (N-1) bytes and points to Nth byte of the data.

b. In file, byte numbering starts from 0. Therefore, if we want to remove N bytes, move the pointer by N bytes.

fseek(fid, N,'bof'); % skips N bytes and points to N+1 byte of the data.

c. The N has to be an integer.

3. Example: 

status =  fseek(fid3, floor(numberOfBytesToSkipFromBOFFor20msIntAlignment), 'bof')

ferror(fid3) ; % ferror gives more information if there is any error during fseek operation.

status = 1 means successful operation else there is an error.

Tuesday 11 March 2014

How to put legends only to some of the lines in a Matlab Plot?

1. Use the 'plot' handles.

x1 = 1:10;
y1blue = 2 .* x1;


y2green = 2 .* y1;

y3red = y2 + 5;

h1 = plot(x1,y1blue ,'b');
hold on;

h2 = plot(y2green,'g');
h3 = plot(y3red,'r');

%Legend all the line plots
legend('Y1blue','Y2green', 'Y3red');


%Legend only Y1 and Y2
legend([h1 h2],{'Y1','Y2'});

2. Another method to control the 'legend content' is given HERE


3. How to use numbers in the legend?

legend({['PRN' num2str(1)],['PRN' num2str(2)]});