필터 지우기
필터 지우기

Could you give me an advice about my error?

조회 수: 3 (최근 30일)
Haksun Lee
Haksun Lee 2012년 7월 13일
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