Error using * Inner matrix dimensions must agree.
古いコメントを表示
Hello, im trying to figure out what is the problem (Error in ArduinoComunication v3(i)=v3(1:i)+((v1(1:i)+v1(1:(i-1)))/2)*(x(1:i)-x(1:(i-1))); ), my 2 vectors have the same size. here is part of the code
v1 = zeros(1,tmax*rate);
v2 = zeros(1,tmax*rate);
v3 = zeros(1,tmax*rate);
while t<tmax
t = toc;
% leer del puerto serie
a = fscanf(s,'%f,%f')';
v1(i)=a(1);
v2(i)=a(2);
v3(i)=v3(1:i)+((v1(1:i)+v1(1:(i-1)))/2)*(x(1:i)-x(1:(i-1)));
% dibujar en la figura
x = linspace(0,i/rate,i);
% velocity
set(l1,'YData',v1(1:i),'XData',x);
set(l2,'YData',v2(1:i),'XData',x);
%set(l3,'YData',v3(1:i),'XData',x);
drawnow
% seguir
i = i+1;
end % code
can you guys tell me what im doing wrong thanks
10 件のコメント
John Chilleri
2017 年 5 月 1 日
It looks like you mean,
v3(i)=v3(1,i)+((v1(1,i)+v1(1,(i-1)))/2)*(x(1,i)-x(1,(i-1)));
Instead of,
v3(i)=v3(1:i)+((v1(1:i)+v1(1:(i-1)))/2)*(x(1:i)-x(1:(i-1)));
So perhaps you've placed : where you should have placed ,?
Hope this helps!
John Chilleri
2017 年 5 月 1 日
編集済み: John Chilleri
2017 年 5 月 1 日
If that's not the mistake, then there are some problems, as you are trying to multiply a row vector by a row vector, which is not possible (unless you want element-wise, in which case you should use .* rather than *). Additionally, you seem to be subtracting/adding two vectors of different lengths, twice. That is, x(1:i)+x(1:(i-1)) are two vectors of different length that can't be subtracted, you do this similarly with v1.
Good luck!
John Prada
2017 年 5 月 1 日
John Chilleri
2017 年 5 月 1 日
I would guess that you have i = 1 to start off, and when it tries to access v1(1,(i-1)) it's attempting to access v1(1,0) which is not an element. This will also be true for the x(1,(i-1)) line.
You'll need to either skip i=1 or figure out how to handle that case!
John Prada
2017 年 5 月 1 日
編集済み: John Prada
2017 年 5 月 1 日
John Chilleri
2017 年 5 月 1 日
I would start with i=2 and place your initial conditions in v1(1),v2(1),v3(1) - these might be zero if you're starting with no movement.
John Prada
2017 年 5 月 1 日
John Chilleri
2017 年 5 月 1 日
編集済み: John Chilleri
2017 年 5 月 1 日
It looks like your i can grow larger than tmax*rate, which is the length of your v1. Accessing v3(i) when i is larger than tmax*rate can cause this error.
I would try deleting the v3(1,i) at the beginning of that line as it doesn't really contribute anything since v3(1,i) was initialized to 0.
John Prada
2017 年 5 月 1 日
John Chilleri
2017 年 5 月 1 日
I hope it's working and producing good results!
Good luck!
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!