How to get rid of zero values for if, str2double command

Hi, my code is as below. There will be two conditions, either : if out(11)=='#' or if out(11)=='%'. The values will be "str2double" to the variables respectively. The problem I encountered is the when out(11)=='%', the values for variables under if out(11)=='#' will be zero. How do I leave it blank so that I can plot the graph without zero values.
s = serial('COM1');
set(s, 'baudrate', 38400)
fopen(s)
out = fscanf(s)
%out='DATA,TIME,#,10006,1.49,1.50,0,0';
totaldata=300;
time=zeros(1,totaldata);
time1=zeros(1,totaldata);
emg_left=zeros(1,totaldata);
emg_right=zeros(1,totaldata);
LF=zeros(1,totaldata);
LB=zeros(1,totaldata);
RF=zeros(1,totaldata);
RB=zeros(1,totaldata);
accelxL=zeros(1,totaldata);
accelyL=zeros(1,totaldata);
accelxR=zeros(1,totaldata);
accelyR=zeros(1,totaldata);
for k=1:totaldata
out = fscanf(s)
if out(11)=='#'
params= regexp(out, '\,', 'split');
time(k)=str2double(params{4});
emg_left(k)=str2double(params{5});
emg_right(k)=str2double(params{6});
LF(k)=str2double(params{7});
LB(k)=str2double(params{8});
end
if out(11)=='%'
params= regexp(out, '\,', 'split');
time1(k)=str2double(params{4});
RF(k)=str2double(params{5});
RB(k)=str2double(params{6});
accelxL(k)=str2double(params{7});
accelyL=str2double(params{8});
accelxR=str2double(params{9});
accelyR=str2double(params{10});
end
end
%plot(time,emg_left');
%plot(time,emg_right');
save('test.mat','time','emg_left','emg_right','LF','LB');
fclose(s)

Answers (1)

Preallocate with nan() instead of zeros()

2 Comments

This won't work as I plot(time,emg_right');.
Why not? Did you try it?

Sign in to comment.

Categories

Tags

Asked:

on 16 Aug 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!