Professional Documents
Culture Documents
Outline(4 stages)
Processes Program Test Improve
Processes
start start+7 end file
word 1
Step 1: Vectorized code Initial values: st=1; ed=st+7; w=1; First copy: ch(:,w)=file(st:ed); Second values: st=st+8; ed=st+7; w=w+1; Second copy: ch (:,w)=file(st:ed);
Step 2: Determine the last value of w while w<=floor(numel(file)/8); copy; end Step 3: Combining step 1 and step 2 st=1; ed=st+7; w=1;lnth=numel(file)/8; while w<=lnth; ch(:,w)=file(st:ed); st=st+8; ed=st+7; w=w+1;end;
Program
% open and read clear all; clc; cd disk:\path\folder fid=fopen(int2str(1),'r'); file=fread(fid,'float'); file; % separation st=1; ed=st+7; w=1; lnth=numel(file)/8; while w<=lnth; ch(:,w)=file(st:ed); st=st+8; ed=st+7; w=w+1; end; % plot subplot(3,1,1),plot(ch(8,:)); %BP subplot(3,1,2),plot(ch(4,:)); %PPG subplot(3,1,3),plot(ch(6,:)); %ECG
Test
Let lnth=1 then compare the first word Let lnth=2 then compare the first two words Let lnth=floor(numel(file)/8) then compare the last word
Improve
Q: What if numel(file) is not an integer multipication of 8 ? Ans: I dont know. Any questions?