how do i save the contentes of a function with out save?
1 view (last 30 days)
Show older comments
vicente simas
on 5 Dec 2018
Commented: vicente simas
on 5 Dec 2018
im doing a project and i have a menu were the button 5 is to save the contents of a function in a new file
-escreve(mtx, assigment, cost); % this is the previous button that grabs a matrix and 2 variables
this is our function 'escreve':
function [] = escreve(matriz, assignment, custo)
fprintf('Custo total --> %.2f', custo);
[desprez, numeroTrabalhadores] = size(matriz);
trinca = length(assignment);
for a = 1: numeroTrabalhadores
custo=matriz(a,assignment(a));
fprintf('\ntrabalhador %d---> tarefa %d (custo %.2f)',a,assignment(a),custo);
end
end
that gives this :
Custo total --> 33.00
trabalhador 1---> tarefa 5 (custo 3.00)
trabalhador 2---> tarefa 3 (custo 3.00)
trabalhador 3---> tarefa 1 (custo 1.00)
trabalhador 4---> tarefa 4 (custo 23.00)
trabalhador 5---> tarefa 2 (custo 3.00)
i wana save what the function gives as a new file but i cannot use save and load
thanks in advance
5 Comments
Accepted Answer
madhan ravi
on 5 Dec 2018
escreve(mtx, assigment, cost); % assuming the input arguments are already defined
function escreve(matriz, assignment, custo)
fprintf('Custo total --> %.2f', custo);
[desprez, numeroTrabalhadores] = size(matriz);
trinca = length(assignment);
fileID = fopen('sample.txt','w');
for a = 1: numeroTrabalhadores
custo=matriz(a,assignment(a));
fprintf(fileID,'\ntrabalhador %d---> tarefa %d (custo %.2f)',a,assignment(a),custo);
end
fclose(fileID)
end
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!