"Subscripted assignment dimension mismatch" error in serial communication
Afficher commentaires plus anciens
i am trying to read data from serial communication and store it in a array but it gives me error as "Subscripted assignment dimension mismatch" i dont understand whats the problem . I am reading 1 byte at a time and storing it in array, code:-
i=1;
while(1)
if(s.BytesAvailable>0)
a=fscanf(s,'%i',1);
t(i)=a; // the error appears for this line
x = linspace(0,10,100);
plot(x,t);
i=i+1;
end
end
1 commentaire
Geoff Hayes
le 1 Mar 2015
Sharan - does the error on the first iteration of the while loop or on some future iteration? Try debugging this problem as follows: in the Command Window, type
dbstop if error
which will invoke the debugger and pause the running code at the line that is generating the error. When this happens (and so after you have called your code) look at the variable t and the variable a. What are the dimensions of each?
A simple way to create the Subscripted assignment dimension mismatch error is to do something like
t = zeros(2,3);
t(1,2) = [1 2];
In the above, we try to assign a two element vector to a single element within t. Something similar may be happening with your code.
Réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!