Array indices must be positive integers or logical values.

6 ビュー (過去 30 日間)
muhammad choudhry
muhammad choudhry 2021 年 4 月 20 日
コメント済み: muhammad choudhry 2021 年 4 月 21 日
Hi,
I am getting the error using the code given below, can anyone help me please. I have negative values in the graph as well I think that is why it happening but I do not know how to resolve this problem.
Code:
close all; clear all; clc;
a=readmatrix('perf_7.ods');
x=a(:,10);
y=a(:,4);
for k=1:length(x)
plot(x(k),y(k),'x','LineWidth',0.5);
hold on
plot(x(1:k),y(1:k),'x','LineWidth',0.5);
drawnow
xlim([0 6])
ylim([0 0.8])
F(i)= getframe(gcf);
pause(0.1)
end
video = VideoWriter ('Graph.avi','Uncompressed AVI')
open(video)
writeVideo(video,F);
close(video)
Error:
Array indices must be positive integers or logical values.
Error in Graph_ani1 (line 16)
F(i)= getframe(gcf);
  1 件のコメント
Weixin Wang
Weixin Wang 2021 年 4 月 20 日
You index variable seems to be 'k', not 'i'.

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

採用された回答

Jan
Jan 2021 年 4 月 20 日
The error message means, that in F(i), the i has its default value, which is the imagninary unit.
As Weixin Wang has mentioned already, the solution is to replace this by "F(k)".
If you get such troubles in the future, use the debugger to find the reasons. Type this in the command window:
dbstop if error
and run your code again. When Matlab stops at the error, check the locally used variables.
gcf
getfram(gcf)
i
F(i)
By the way, omit the brute clearing header
close all; clear all; clc;
to improve the quality of your code. Is there a reason to close figures opened by other functions? This could destroy work. clear all removed not only all variables, but clears all functions from the memory also. Reloading them from the disk wastes time without any benefit.
  1 件のコメント
muhammad choudhry
muhammad choudhry 2021 年 4 月 21 日
thanks alot for the suggestions.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by