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!