Could you give me an advice about my error?

3 次查看(过去 30 天)
I am trying to put the data into cell space through serial communication.... I have 2 computer. One computer give another computer serial data. I added following code.
Computer 1.
s=serial('COM7')
fopen(s)
while(1)
fwrite(s,[242 1 2 1 2 1 1 246])
end
Computer 2.
s=serial('COM8')
fopen(s)
a=fread(s,50)
j=0;
data=cell(1,20);
ch=1;
for i=1:1:49
ch=a(i)
if(ch==242)
data(1)=ch;
j=1;
elseif(ch==246)
data(j)=ch;
break
else
data(j)=ch;
j=j+1;
end
end
}
Above code is to get the data through seial but I have problem in here.
Error message is "Conversion to cell from double is not possible.
How can I change my code to eliminate error...
I don't know which part is wrong..
Please help me. Thank you for reading.

回答(2 个)

Walter Roberson
Walter Roberson 2012-7-13
Not data(1)=ch; but data{1}=ch; if you are going to use data as a cell array.
Are you sure you want to assign to position #1 of data and not to position #j ?
I do not at the moment see any reason why you would not use a character or numeric array instead of a cell array, though.

Haksun Lee
Haksun Lee 2012-7-13
Thank you for your answer.. As you say, I'd like to use a character or numeric array instead of a cell array.
Which command can I use in order to numeric array?
I always appreciate your concern..

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by