I have this error. When I call a function in another function this error pull up:
Output argument "matrix" (and maybe others) not assigned during call to "ChargerMatrice".
Error in OptimiserChemin (line 10)
[matrix] = ChargerMatrice (choixOption);
However when I run the function called only, the Command Window display my matrix correctly.
My function where I call the other function is this one:
function [unChemin,cheminPossible] = OptimiserChemin ()[tab,tf] = CreerTrajet ();borne1 = tab(1);borne2 = tab(2);autonomie = tab(3);choixOption = 1;[matrix] = ChargerMatrice (choixOption); %this line causing the error
matrixDistance = matrix;choixOption = 2;[matrix] = ChargerMatrice (choixOption);matrixDuree = matrix;distance = matrixDistance(borne1,borne2);duree = matrixDuree(borne1,borne2);
and the function called is :
function [matrix] = ChargerMatrice (choixOption) if (choixOption == 1) file = fopen('MatriceDistances.txt', 'rt'); if file ~= -1 maintable1 = readmatrix('MatriceDistances.txt'); maintable1(1,:) = []; maintable1(:,1) = []; matrix = maintable1; %the variable matrix is there
fclose(file); elseif (choixOption == 2) file = fopen('MatriceDurees.txt', 'rt'); if file ~= -1 maintable2 = readmatrix('MatriceDurees.txt'); maintable2(:,1) = []; matrix = maintable2; %the variable matrix is there fclose(file); else fprintf('Erreur! Veuillez choisir un nombre entre 1 et 2 correspondant à la matrice à afficher'); end end endend
Best Answer