The end operator must be used within an array index expression

How to fix this error:
The end operator must be used within an array index expression.
Error in .... (line 17)
shot = shot(101:end,1);

7 件のコメント

KSSV
KSSV 2020 年 9 月 15 日
編集済み: KSSV 2020 年 9 月 15 日
What is shot in the code? You cannot input it in to a function.
Nisar Ahmed
Nisar Ahmed 2020 年 9 月 15 日
[Shot, dathdr] = ReadRSS('Pshot.rss');
KSSV
KSSV 2020 年 9 月 15 日
What is Shot? It is an array?
Nisar Ahmed
Nisar Ahmed 2020 年 9 月 15 日
Yes
KSSV
KSSV 2020 年 9 月 15 日
That case it should not throw error. We cannot help unless complete code is shown.
Nisar Ahmed
Nisar Ahmed 2020 年 9 月 15 日
[vp,modhdr] = (ReadRSS('Vp.rss'));
vp = squeeze(vp(1,1,:));
% pad vp with more samples in order to make at least 5 seconds of VRMS
vp = [vp; ones(1500,1)*vp(end)];
[nz] = size(vp,1);
dx = modhdr.geometry.D(1);
dz = modhdr.geometry.D(3);
%% Read data and get sizes
[Shot, dathdr] = ReadRSS('Pshot.rss');
shot = shot(101:end,1);
[nt, ntr] = size(Shot);
dt = dathdr.geometry.D(1);
time_i = (0:nt-1)*dt;
time_i = time_i.';
KSSV
KSSV 2020 年 9 月 15 日
What is size of Vp.rss? Is it taking matrix inside the function?

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

 採用された回答

Steven Lord
Steven Lord 2020 年 9 月 15 日

1 投票

The identifiers shot (all lower-case) and Shot (first letter capitalized) are two different things in MATLAB. Did you mean to index into Shot instead of shot?

3 件のコメント

Nisar Ahmed
Nisar Ahmed 2020 年 9 月 15 日
Thank you for pointing out first letter capital issue. However, the correct code is like this one
Shot = Shot(101:end, :);
MUNEEB AHMAD
MUNEEB AHMAD 2022 年 5 月 18 日
編集済み: MUNEEB AHMAD 2022 年 5 月 18 日
The end operator must be used within an array index expression.
Error in test2 (line 5)
BER(i)=ber(end,1);
This is the code.
gama_dB=0:0.5:10;
for i=1:length(gama_dB)
g_dB=gama_dB(i);
sim('Bpsk2')
BER(i)=ber(end,1);
end
Why is this error coming here? plese help.
Steven Lord
Steven Lord 2022 年 5 月 18 日
Nothing in your code defines a variable named ber. Do you have a function named ber accessible to MATLAB? If so that last command inside the for statement tries to call that function with end and 1 as the two inputs. But MATLAB doesn't know how to interpret end in that context and so throws an error.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by