"index exceeds matrix dimensions" when using str2double
Mostrar comentarios más antiguos
Hi guys.
I am currently attempting to receive data from Arduino and saving them into a Matlab array. I'm not sure why, but I got stuck in an error "index exceeds matrix dimensions" while trying to save str2double value into an array location. I'm wondering if this is because I'm not allowed to save any double values into an array? How should I come across this :( Below I've attached my code.
Thanks in advance.
//////////////////////////////////////
clc
clear s
delete(instrfindall);
%initializing port connection
s=serial('COM7','BaudRate',9600,'DataBits',8);
s.StopBits=1;
fopen(s);
%receiving text info from COM7
n=10;
array=zeros(n,3);
for i=1:n
fprintf(s,'*IDN?');
answer = fscanf(s)
angle=textscan(answer,'%c %s %s %s %c');
array(i,1)=str2double(angle{i,3});
array(i,2)=str2double(angle{i,4});
array(i,3)=str2double(angle{i,5});
end
%converting string info to double and saving them into array
fclose(s);
delete(s)
clear s
5 comentarios
KSSV
el 27 de Jul. de 2017
What is size(angle) ? before and after str2double?
Jan
el 27 de Jul. de 2017
@Jaz: Please post the complete error message, such that the readers do not have to guess, in which line the error occurres.
Heejin Kim
el 27 de Jul. de 2017
Heejin Kim
el 27 de Jul. de 2017
Jan
el 27 de Jul. de 2017
@Jaz: See my answer: Then you need "angle{3}" and not "angle{i,3}".
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!