Array indices must be positive integers or logical values.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
muhammad choudhry
le 20 Avr 2021
Commenté : muhammad choudhry
le 21 Avr 2021
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 commentaire
Réponse acceptée
Jan
le 20 Avr 2021
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!