Could you give me an advice about my error?
1 次查看(过去 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.
0 个评论
回答(2 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!