can someone please help me understand this error?
Afficher commentaires plus anciens
why this give me this
Matrix index is out of range for deletion.
Error in del_emp (line 14)
Age(i)=[];
function [] = del_emp (e)
emp=R_Data();
i = search_emp (e);
if i>0
Name = emp.Name;
ID = emp.ID;
Age = emp.Age;
Employee_Position = emp.Employee_Position;
Years_of_Exeperience = emp.Years_of_Exeperience;
Status = emp.Status;
Name(i) = [];
ID(i)=[];
Age(i)=[];
Employee_Position(i)=[];
Years_of_Exeperience(i)=[];
Status(i)=[];
n = length (ID);
name1 = string (Name);
po1 = string (Employee_Position);
status1 = string(Status);
fid = fopen('C:\Users\ibrah\Desktop\me.txt', 'w');
for j=1:n
fprintf(fid,'%s \t %d \t %d \t %s \t %d \t %s \n',name1(j),ID(j), Age(j), po1(j), Years_of_Exeperience(j), status1(j));
end
fclose (fid);
else
disp('oOps!!..Invalid entry as the employee is not Existed');
end
end
1 commentaire
Manikanta Aditya
le 23 Avr 2024
The error message “Matrix index is out of range for deletion” typically occurs when you’re trying to delete an element at an index that doesn’t exist in the matrix. In your case, it seems like the error is occurring at the line
Age(i)=[];.
This could be happening because the index i returned by the search_emp(e) function is greater than the length of the Age array. It’s also possible that search_emp(e) is returning 0 or a negative number, which would also be an invalid index.
Réponses (0)
Catégories
En savoir plus sur Matrix Indexing 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!