Could you give me an advice about my error?

1 visualización (últimos 30 días)
Haksun Lee
Haksun Lee el 13 de Jul. de 2012
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.

Respuestas (2)

Walter Roberson
Walter Roberson el 13 de Jul. de 2012
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 el 13 de Jul. de 2012
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..

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by