Why this error is coming in my code?
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
zeros(1500,2);
for j=1:3
zeros(j,1)=randi([1,5],1,1);
zeros(j,2)=randi([1,5],1,1);
end
ones(1500,2);k=0;
if true
% code
end
while k<365
ones(k,1) = 1*2*zeros(k,1);% i have assumed velocity in x direction to be 2m/d.
ones(k,2) = 1*1*zeros(k,2);% velocity in y direction is assumed to be 1m/d.
end
Subscript indices must either be real positive integers or logicals.
Error in oncemore (line 8) ones(k,1) = 1*2*zeros(k,1);% i have assumed velocity in x direction to be 2m/d.
Réponses (1)
Azzi Abdelmalek
le 26 Juin 2015
There are many problems in your code The first line:
zeros(1500,2);
What this line means? then after you wrote
zeros(j,1)=randi([1,5],1,1)
Which will destroy the built-in function zeros
3 commentaires
anchal garg
le 26 Juin 2015
Modifié(e) : anchal garg
le 26 Juin 2015
Azzi Abdelmalek
le 26 Juin 2015
Modifié(e) : Azzi Abdelmalek
le 26 Juin 2015
m=4
n=2
a=randi(5,m,n)
@anchal, assuming it's the first run of your script, the line
zeros(1500,2);
means Create a matrix of zeros of size 1500x2 and because I don't store it anywhere, immediately forget about it. Basically, it does nothing but waste time.
You then go on to create a variable call zeros which will prevent the built-in matlab zeros function from working.
You then do the exact same thing with ones. Invoke the function, but do nothing with the output and then prevent the function from working again (until you clear your variables)
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!