when output, matlab shows <missing>?

I wrote a recursive function to generate a car plate for each car
function plate=plates(n,plate)
if n<1
return
else
element=["1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
str1=element(randi([11,36]));
for i=1:5
str2=element(unidrnd(36));
str1=strcat(str1,str2);
end
plate(n)=str1;
plates(n-1,plate);
end
end
In my project, some of the cars are allowed to jump the red light, and I use an array 'jaywalk', whose original value is all 0, to record them:
if the car will jump the red light, jaywalk(1,i)=1;,i is the numerical order of the car
At the end of my project, I need to display the plate of the cars which jumpt the red light, n is the total number of cars
for i=1:n
if jaywalk(1,i)==1
disp(plate(i));
end
end
BUT when I run the code to the stage of displaying the car plates, matlab shows missing.
how can i solve the problem?
Any help will be appreciated! Thanks!

1 commentaire

In my project, I use this to call out the function
plate=["0"];
plate=plates(n,plate);

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 11 Oct 2020

0 votes

plates(n-1,plate);
That is not an assignment statement.

4 commentaires

Thank you! And I modified it into
plate(n-1)=plates(n-1,plate);
but matlab says 'Unable to perform assignment because the left and right sides have a different number of elements.'
I really don't know how to modify that code, could you help me in detail? Thanks a lot!
Walter Roberson
Walter Roberson le 12 Oct 2020
What is the grammar for plates? Your existing code suggests that you start with a letter and then have 5 characters that are letters or digits. Why are you going recursive?
越琪 吴
越琪 吴 le 12 Oct 2020
yes, a car plate is composed of a letter and then 5 characters of letters or digits. I am going recursive because I need to generate a car plate for each of the n cars, I know this can be achieved by a loop, but recursion is demanded by my instructor. Thanks!
Walter Roberson
Walter Roberson le 12 Oct 2020
I suggest that you read https://www.mathworks.com/matlabcentral/answers/579063-code-for-reverse-a-vector#comment_998227

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by