error message 'The end operator must be used within an array index expression.'
이전 댓글 표시
Hi,
When I try to plot
plot(H20Vs{1:end,1},H20Vs{1:end,2})
hold on
plot(M20Vs{1:end,1},M20Vs{1:end,2})
hold on
plot(N20Vlin{1:end,1},N20Vlin{1:end,2})
% hold on
% plot(P20Vs{1:end,1},P20Vs{1:end,2})
legend('a' ,'b', 'c', 'd', 'e', 'f', 'h', 'l', 'm', 'n')
I recieve this error message 'The end operator must be used within an array index expression.'
Does anyone have any idea why this could be happening? I noticed the last two plot functions don't cause this issue, only the first one.
Cheers
답변 (1개)
It is likely that the error is in code before what was posted. For example,
a(end)=1
This error occurs because end was used to index an array that does not exist yet.
댓글 수: 3
Walter Roberson
2025년 7월 4일
plot(H20Vs{1:end,1},H20Vs{1:end,2})
This code is very likely wrong, unless H20Vs is a 1 x N cell array for N >= 2.
If H20Vs is a 2 x something cell array, then H20Vs{1:end,1} would do cell array expansion of H20Vs{1,1}, H20Vs{2,1}, H20Vs{3,1} and so on, inserting all of the values "in place" in the command line, and then would do the same thing for H20Vs{1,2}, H20Vs{2,2}, H20Vs{3,2} and so on. The result would be as-if the call
plot(H20Vs{1,1}, H20Vs{2,1}, H20Vs{1,2}, H20Vs{2,2})
had been made. This would plot H20Vs{1,1} against H20Vs{2,1} and H20Vs{1,2} against H20Vs{2,2}. The code would not plot H20Vs{1,1} against H20Vs{2,1} and then plot H20Vs{2,1} against H20Vs{2,2} and so on.
Stephen23
2025년 7월 4일
H20Vs might be a table, in which case that syntax does not generate a comma-separated list.
Walter Roberson
2025년 7월 4일
Good point about tables.
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!