The end operator must be used within an array index expression

35 ビュー (過去 30 日間)
Julián Adán
Julián Adán 2022 年 10 月 10 日
編集済み: Jan 2022 年 10 月 11 日
need to solve please this error:
The end operator must be used within an array index
expression.
Error in clases y comandos (line 166)
y(1:end,1) - y(2:end);
this is the code:
a=arduino
fs=1500
N=1000
d=zeros(N,1)
t=linspace(0,(N-1)/fs,N)
t=transpose(t)
z=zeros(N,1)
entrada=line(nan,nan,'color','g','linewidth',0.5)
salida=line(nan,nan,'color','r','linewidth',0.5)
ylim([-0.1,5.1])
xlim([0 (N-1)/fs])
grid
stop=1
uicontrol('Style','pushButton','String','FINALIZAR','Callback','Stop = 0;')
tic
while stop
if toc < 1/fs
tic
y(1:end-1) = y(2:end-1);
y=readVoltage(a,'A0')
set(entrada,'Xdata',t,'Ydata',y)
z(1:end) = z(2:end)
z=readVoltage(a,'A1')
set(salida,'Xdata',t,'Ydata',z)
drawnow
end
%
end
  3 件のコメント
Jan
Jan 2022 年 10 月 10 日
Please post the relevant part of the code and a copy of the complete error message. This is not the complete line:
y(1:end,1) - y(2:end);
Jan
Jan 2022 年 10 月 11 日
編集済み: Jan 2022 年 10 月 11 日
Please do not let the readers guess, which one is the line 166. The mentioned line "y(1:end,1) - y(2:end);" does not occur in the shown code. the cyclist hits the point, that "y(1:end,1) = y(2:end)" is meant.
I've formatted your code. You can use the tools above the field for editing by your own in the future.

サインインしてコメントする。

回答 (1 件)

the cyclist
the cyclist 2022 年 10 月 10 日
編集済み: the cyclist 2022 年 10 月 10 日
In your code, you have not yet created any variable named y, before you call this line:
y(1:end-1) = y(2:end-1)
The end operator must be used within an array index expression.
Therefore, you get this error message because you cannot index a variable that does not exist.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by