필터 지우기
필터 지우기

Printing output result given different input

조회 수: 3 (최근 30일)
Chiara Lanzi
Chiara Lanzi 2023년 7월 27일
답변: Chiara Lanzi 2023년 8월 1일
Hello everyone,
I am trying to print in txt files the outputs calculate from a code which is simulating an inversion.
I managed to print the output (let's called it model) if I include only one input variable by using the dlmwrite function (dlmwrite('Model.txt', [model ],'Delimiter',' ','precision','%.4f'))).
The code allows to run the inversion with more than one input variable so the variable named model has two results; it calculates the results considering the input file 1 and the input file 2 at the same time. At this point, I would like to print in two separate files the outputs from the two input variables. If I used the dlmwrite funtion as I wrote before I got only one result (the second variable result) but not both.
Do you have some suggestion to how use the dlmwrite function to print both?
Chiara

답변 (2개)

Walter Roberson
Walter Roberson 2023년 7월 27일
dlmwrite can only write to one file in any given call.
dlmwrite('Model_1.txt', First_Variable, 'Delimiter', ' ', 'precision', '%.4f')
dlmwrite('Model_2.txt', Second_Variable, 'Delimiter', ' ', 'precision', '%.4f')
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 7월 28일
There is no such thing as an if loop.
If executes a section of code 0 or 1 times
for executes a section of code a pre-determined number of times (unless ended prematurely)
while executes a section of code an undetermined number of times, until conditions change or ended prematurely.
Walter Roberson
Walter Roberson 2023년 7월 28일
I suspect the answer you are looking for is:
filename = sprintf('Model_%d.txt', LOOP_COUNTER_VARIABLE_GOES_HERE);
dlmwrite(filename, DATA_VARIABLE_NAME_GOES_HERE, 'Delimiter', ' ', 'precision', '%.4f');

댓글을 달려면 로그인하십시오.


Chiara Lanzi
Chiara Lanzi 2023년 8월 1일
Dear Walter,
thanks for your suggestion. I tried but it's still not working. I can print two files but they have the same solution.
Anyway, I'll work more on t his and thanks agian on your suggestion.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by