how do i save the contentes of a function with out save?

1 view (last 30 days)
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
Walter Roberson
Walter Roberson on 5 Dec 2018
Is there a reason not to use the functions the professor suggested ?
vicente simas
vicente simas on 5 Dec 2018
we can not use the load and save function and dlm as well because either are not in the book or are restricted for this project so the hint was to use fopen the fprintf and then fclose

Sign in to comment.

Accepted Answer

madhan ravi
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)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!